MATLAB newbie: how to index a string array?

In summary, Indexing in MATLAB refers to accessing and manipulating specific elements within an array or matrix. It allows you to retrieve or modify individual values or subsets of data within a larger data structure. To index a string array in MATLAB, you can use either single or double quotation marks surrounding the string. Yes, you can use logical indexing with string arrays in MATLAB. This allows you to filter the array based on certain conditions, such as only selecting strings that contain a specific character or word. To change the contents of a specific string in a string array, you can use the same indexing methods as mentioned before. First, access the string you want to change, then assign a new value to that element. Some useful functions for indexing string arrays in MATLAB
  • #1
bzz77
34
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
  • #2
It should be:
header(1) = {'Jill'}
 

Related to MATLAB newbie: how to index a string array?

1. What is indexing in MATLAB?

Indexing in MATLAB refers to accessing and manipulating specific elements within an array or matrix. It allows you to retrieve or modify individual values or subsets of data within a larger data structure.

2. How do I index a string array in MATLAB?

To index a string array in MATLAB, you can use either single or double quotation marks surrounding the string. For example, if you have a string array called "myStrings", you can access the first element by using myStrings(1) or myStrings('1').

3. Can I use logical indexing with string arrays in MATLAB?

Yes, you can use logical indexing with string arrays in MATLAB. This allows you to filter the array based on certain conditions, such as only selecting strings that contain a specific character or word.

4. How do I change the contents of a specific string in a string array?

To change the contents of a specific string in a string array, you can use the same indexing methods as mentioned before. First, access the string you want to change, then assign a new value to that element. For example, myStrings(1) = 'New Value'.

5. What are some useful functions for indexing string arrays in MATLAB?

Some useful functions for indexing string arrays in MATLAB include strfind(), which allows you to find the index of a specific character or substring within a string, and strcmp(), which compares two strings and returns a logical value indicating if they are equal or not.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
4K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
18
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • Programming and Computer Science
Replies
7
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
Back
Top