Convert numbers in a 1x1 string to an array.

조회 수: 6 (최근 30일)
Rio Smitham
Rio Smitham 2011년 6월 7일
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.

채택된 답변

Robert Cumming
Robert Cumming 2011년 6월 7일
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
Rio Smitham
Rio Smitham 2011년 6월 7일
Thanks, that's really helped. I managed to delete the unwanted text and then use the strread function to convert it :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile 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