1

I want to split a string using "," as delimiter but I'm not able. I tried:

temp = textscan('the first","the second','%s',2,'Delimiter','","');

but the result is:

temp{:}

ans = 'the first'

Shahzad Barkati
  • 2,532
  • 6
  • 25
  • 33
FrancescoVe
  • 1,060
  • 1
  • 7
  • 12

1 Answers1

0
temp = textscan('the first","the second','%s',5,'Delimiter',{'","'});

I am unable to find the relevant part of the documentation, but with an array of chars textscan uses each char as an individual delimiter. Check temp = textscan('the first","the second','%s',4,'Delimiter','","'); to se how the delimiter is interpeded in your code.

Daniel
  • 36,610
  • 3
  • 36
  • 69
  • 1
    Thank you, now it is more clear. I still appreciate any help to solve my problem, since I want to separate my strings only with "," and not with " or , >> temp = textscan('the first","the second','%s',5,'Delimiter',{'","'}) ??? Error using ==> textscan Delimiter must be a string. >> temp = textscan('the first","the second','%s',4,'Delimiter','","') temp = {4x1 cell} >> temp{:} ans = 'the first' '' '' 'the second' – FrancescoVe Mar 26 '15 at 14:54
  • @FrancescoVe: In recent versions [textscan](http://www.mathworks.com/help/matlab/ref/textscan.html#namevaluepairarguments) supports cell arrays or strings, I don't know when this was changed but what matlab version are you using? – Daniel Mar 26 '15 at 15:15
  • 2008a. I cannot even use the function strsplit and I think it's time to move to a newer version :) However I've just realized that in the meanwhile I can easily handle the splitting problem with Python. – FrancescoVe Mar 26 '15 at 15:42
  • @FrancescoVe: `regexp` might be an alternative. With only an old license available I would switch to octave which basically supports the same language. Since last update it comes with a nice UI (`--force-gui`). – Daniel Mar 26 '15 at 15:54
  • Thank you @Daniel, your help was extremely useful and now I can go on with my work. – FrancescoVe Mar 27 '15 at 10:25