MATLAB: How to copy a part of characters from each cell to a new matrix

matrixmatrix manipulation

From a first matrix, I isolated the cells that interested me and I copied them in a new matrix.
[1] 1601|192(24.7°|28.5TM°)
[2] 983|741(6.85°|276.53TM°)
[x] 1114|243(11.33°|62.59TM°)
In a third matrix, I wanted to isolate a part of characters from each cell into two columns:
For example,
[a] [b]
[1] 24.7 28.5
[2] 6.85 276.53
[x] 11.33 62.59
I don't know if it is better to do a loop (for… end) or something else…
Someone can help me?
Thank you in advance.

Best Answer

  • This is most likely the fastest way to convert to numeric:
    >> inp = {'1601|192(24.7°|28.5TM°)','983|741(6.85°|276.53TM°)','1114|243(11.33°|62.59TM°)'};
    >> fmt = '%*f|%*f(%f°|%fTM°)';
    >> mat = sscanf(sprintf('%s',inp{:}),fmt,[2,Inf]).'
    mat =
    24.7000 28.5000
    6.8500 276.5300
    11.3300 62.5900