cell containing strings outputs only dots
조회 수: 1 (최근 30일)
이전 댓글 표시
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
답변 (1개)
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Type Conversion에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!