Data conversion cell to double and char

3 views (last 30 days)
Mekala balaji
Mekala balaji on 22 Nov 2014
Commented: Guillaume on 22 Nov 2014
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.

Answers (1)

Guillaume
Guillaume on 22 Nov 2014
You're using str2double on your strings as well. Only use it for numbers and leave the strings as is.
  2 Comments
Mekala balaji
Mekala balaji on 22 Nov 2014
It is a single column, how can I covert part of the column to double
Guillaume
Guillaume on 22 Nov 2014
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

Sign in to comment.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!