Borrar filtros
Borrar filtros

cell containing strings outputs only dots

1 visualización (últimos 30 días)
Thms
Thms el 6 de Jun. de 2012
Respondida: Suryaansh Mata el 18 de Jun. de 2019
hi there,
i have a small issue concerning the conversion from a cell containing strings to numbers. I am aware of str2double, but I would like to speed the process up. I tried what was suggested in another thread of this forum, however, this results in the following problem:
My cell data{1} looks like this (in fact, it's way longer than that):
data{1}(1:5)
ans =
'11493520'
'11493521'
'11493522'
'11493523'
'11493524'
So I can convert the contents of the cell to numbers using these lines of code:
C = data{1};
S = sprintf('%s*', C{:});
samples(:,icell) = sscanf(S, '%f*')';
This works fine. However, when I try to access the second cell, MATLAB fails to read out the content properly. data{2} has the following content:
ans =
'448.2'
'448.0'
'448.0'
'448.6'
'449.2'
If I try to access the cell with data{2}(1:5) i get 5 rows with dots as an output:
data{2}(1:5)
ans =
'.'
'.'
'.'
'.'
'.'
Could someone please tell me what is going wrong here? Thanks a lot!
Cheers, Tom

Respuestas (1)

Suryaansh Mata
Suryaansh Mata el 18 de Jun. de 2019
The command 'sprintf' just changes the display formatting of the strings. Rather use str2double and str2num inside 2 loops. Run one loop for the number of cells in the data and the other for each string array that is contained in each cell of data. That should be a nice workaround for this

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by