2

Inside a Matlab function I need something like (as you can imagine in real life it should be represented as a for loop):

var(1) = 'First string';
var(2) = 'Second string';
...
var(i) = 'i-th string';

Alas, I can't do this cause var(1) should contain just a character (not an entire string) and I get:

??? Subscripted assignment dimension mismatch.

I've searching on the web, but I can't find a good solution, any ideas?

1

1 Answer 1

6

Use a Matlab cell array:

var{1} = 'first string';
var{2} = 'second string';
var{n} = 'nth string';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.