Convert numbers in a 1x1 string to an array.

5 views (last 30 days)
I'm currently using MATLAB to read data directly from an instrument using the instrument toolbox. The problem I'm having is that when i read the data in, it brings it into MATLAB into a 1 x 1239 char string. This means i have all my data stored as text in the same 'cell', only separated by spaces. E.g in cell (1,1) of variable A there is: V 0, 100 -0.001 -0.01 -0.02........ #END Is there any way to take this data, convert it to number and put it into an array?
Please note i have tried str2num, str2mat, cell2mat etc and these do not work because the data i have is all in the same 1x1 'cell'
Thanks in advance for your help.

Accepted Answer

Robert Cumming
Robert Cumming on 7 Jun 2011
is your format fixed or is it variable (i.e. the amount of numbers you will have). Do you have a comma after the 1st 0 or is it a typo? The answers to this will determine how much preprocessing you may have to do.
If you can remove the V and the end of the line, so that its a text line only containing numbers (or at least with the same delimited) you could use:
strread ( line, '%f' )
  1 Comment
Rio Smitham
Rio Smitham on 7 Jun 2011
Thanks, that's really helped. I managed to delete the unwanted text and then use the strread function to convert it :)

Sign in to comment.

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!