Reputation: 221
I am reading a string of the form: Text1_Text2_Text3_Text4
. I do a textscan
with the delimiter "_"
:
myString = textscan('Text1_Text2_Text3_Text4', '%s', 'delimiter','_');
output:
'Text1'
'Text2'
'Text3'
'Text4'
This is a char array. To transform it to a String I use myString = myString{1}
.
I want to know the size of the second index -> numel(myString(2));
But MATLAB always returns 1. Where am I wrong?
Thanks in advance.
P.S. It works if I do
myString = myString{1}(2);
myString = myString{1};
But I would need a lot of variables if I also want to know the size of index 1, 3 or 4 so there must be an easier way.
Upvotes: 0
Views: 53
Reputation: 112759
To know the size of all strings:
>> sizes = cellfun(@numel, myString)
>> sizes =
5
5
5
5
To know the size of the k
-th string only:
>> k = 2;
>> numel(myString{k})
>> ans =
5
Upvotes: 1