cell containing strings outputs only dots

1 回表示 (過去 30 日間)
Thms
Thms 2012 年 6 月 6 日
回答済み: Suryaansh Mata 2019 年 6 月 18 日
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

回答 (1 件)

Suryaansh Mata
Suryaansh Mata 2019 年 6 月 18 日
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

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by