MATLAB newbie: how to index a string array?

Click For Summary
SUMMARY

The discussion focuses on indexing and modifying string arrays in MATLAB, specifically using cell arrays to store strings. The user encountered an error when attempting to assign a string directly to an indexed position in a cell array. The correct method to change an element in a cell array is demonstrated as: header(1) = {'Jill'}. This solution allows for the dynamic modification of string elements within the array.

PREREQUISITES
  • Basic understanding of MATLAB syntax and data structures
  • Familiarity with cell arrays in MATLAB
  • Knowledge of string manipulation in MATLAB
  • Experience with indexing in MATLAB arrays
NEXT STEPS
  • Explore MATLAB cell arrays and their functionalities
  • Learn about string manipulation functions in MATLAB
  • Research best practices for managing dynamic data structures in MATLAB
  • Investigate the differences between cell arrays and regular arrays in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB beginners, data analysts, and developers who need to manipulate string data within MATLAB applications.

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

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 18 ·
Replies
18
Views
6K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K