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!