MATLAB: How can i seperate numbers from strings while using textscan


I want to store this data in a cell using textscan:
My code is
But matlab handles "OE,-300,150" as one string. I want matlab to handle it as 1 string, followed by 2 numbers. How can I do that?

Best Answer

  • >> str = '2000,146.557,OE,-300,150 2000,146.625,FOB,0,0';
    >> textscan(str,'%f%f%s%f%s%f%s%f%f','Delimiter',',')
    ans =
    Columns 1 through 7
    [2000] [146.557] {1x1 cell} [-300] {1x1 cell} [146.625] {1x1 cell}
    Columns 8 through 9
    [0] [0]
    If you edit your question and upload the data file using the paperclip button then I can also show you how to make it work for your file.
    Note that the 150 2000 is parsed as one string, because you did not put a comma. Is this a mistake?