0

I created an array of strings and I want to get the value of a given string at a given position, but the returned value is the character and not the string, eg:

myArray = ['string1' 'string2' 'string3'];
s = myArray(1); //returns the character at the position 1, instead of the string

How can I get the value of these strings based on a given position i ?

2 Answers 2

1

Try using a cell array:

myArray = {'string1' 'string2' 'string3'};
s = myArray{1};
Sign up to request clarification or add additional context in comments.

Comments

0

You can do a for loop if this is what you are asking for.

myArray=['b' 'c' 'd']
for i =1:lenght(myArray)
s(i)=myArray(i);

end

Not sure what you are asking for exactly.

1 Comment

Thanks, the correct answer to my question is above :) s=myarray{1}='string1' and not 's' which is the first character. I wanted to get the first string.

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.