Convert numbers in a 1x1 string to an array.

7 visualizaciones (últimos 30 días)
Rio Smitham
Rio Smitham el 7 de Jun. de 2011
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.

Respuesta aceptada

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by