cell containing strings outputs only dots
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (1)
Suryaansh Mata
am 18 Jun. 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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!