Data conversion cell to double and char
조회 수: 4 (최근 30일)
이전 댓글 표시
I have the following data
column values as follows (in Cell format): in the file name of: Data_All{j}{k,1}
2.3 mm
4.6 %
Normal
False Alarm
But I want store as below
2.3--> Double
4.6--->Double
Normal
False Alarm
When I use
for k=1:size(Data_All{j},1)
Data_Allfinal{j}{k,1}=Data_All{j}{k,1};
final11=strsplit(char(Data_Allfinal{j}{k,1}), ' ');
f31{j}{k,1}=str2double(char(final11(1)));
end
it is returning as below
2.3--->Double
4.6-->Double
NaN
NaN
Can some one help me how to store numerical values in double format, and other as char form (I want to avoid NaN (keep their original as such)
Thanks in advance.
댓글 수: 0
답변 (1개)
Guillaume
2014년 11월 22일
You're using str2double on your strings as well. Only use it for numbers and leave the strings as is.
댓글 수: 2
Guillaume
2014년 11월 22일
One way to do it would be copy the whole cell array and then only replace the columns you want to convert with the for loop:
f31{j} = Data_all{j}
colstoconvert = [1, 2]; %following your example
for col = colstoconvert
splitrow = strsplit(Data_all{j}{col}, ' '); %no need for char
f31{j}{col} = str2double(splitrow{1}); %no need for char
end
참고 항목
카테고리
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!