0

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.

Baloo
  • 223
  • 4
  • 17

1 Answers1

1

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
Luis Mendo
  • 110,752
  • 13
  • 76
  • 147
  • Almost. I would like to know the size of the second element only. Or to make it more clear, the size changes within the loop, so something like size(k) would be great. Thanks! – Baloo Apr 22 '14 at 14:30