MATLAB MATLAB newbie: how to index a string array?

AI Thread Summary
In MATLAB, when working with cell arrays of strings, attempting to assign a character array directly to an element of a cell array results in a conversion error. To successfully change an element in a cell array, the new string must also be enclosed in curly braces. For example, to replace 'Fred' with 'Jill', the correct syntax is header(1) = {'Jill'}. This ensures that the assignment is compatible with the cell array structure. If the goal is to store and modify strings for a header row in a matrix output, using a cell array is appropriate, as it allows for flexible string manipulation.
bzz77
Messages
33
Reaction score
0
I'm a Matlab newbie. I have an array of strings, for example:

header = {'Fred', 'Tom'}

When I do:
header(1)

I get 'Fred'

I want to be able to change elements--for example:
header(1) = 'Jill'

But I get this error:
? Conversion to cell from char is not possible.

I would be very grateful for advice. If it isn't possible to do this, is there some other container I could use for storing and changing strings? The strings will form a header row for matrix columns output to a file. Thanks a lot.
 
Physics news on Phys.org
It should be:
header(1) = {'Jill'}
 

Similar threads

Back
Top