Convert numbers in a 1x1 string to an array.

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.

 采纳的回答

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 个评论

Thanks, that's really helped. I managed to delete the unwanted text and then use the strread function to convert it :)

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by