Data conversion cell to double and char

4 visualizzazioni (ultimi 30 giorni)
Mekala balaji
Mekala balaji il 22 Nov 2014
Commentato: Guillaume il 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.

Risposte (1)

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

Accedi per commentare.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by