Error in converting Cell array to double
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi,
I'm converting some cell arrays to their equivalent numbers, but have an error for couple of them. I attached the variables to this question.
The problem is in my cell array some elements are 'NaN' and also some other elements have different length.So when I'm using this command to convert:
G8_D=str2num(cell2mat(G8));
C1_D=str2num(cell2mat(C1));
I get this error:
Dimensions of matrices being concatenated are not consistent.
The important matter is 'I can not remove Nan elements and shift all cells up or down because the location of each element is meaningful for me, but that's ok if I get a number like 0 instead of Nan '
I was thinking to maybe add some zeros to the end of elements to make their length equal but couldn't get a good result.
Any idea to how to convert these two cell arrays to number?
Thanks
1 Commento
Stephen23
il 28 Giu 2017
There are no NaN strings in those cell arrays:
>> find(strcmpi(C1,'NaN'))
ans =
Empty matrix: 0-by-1
>> find(strcmpi(G8,'NaN'))
ans =
Empty matrix: 0-by-1
Risposta accettata
Stephen23
il 28 Giu 2017
str2double converts those cell arrays of strings to double:
>> str2double(C1)
ans =
0.23
0.23
0.23
0.23
0.23
0.24
0.23
0.23
0.23
0.24
0.24
0.24
0.24
0.24
0.23
999
0.24
...
0.23
0.24
0.23
0.23
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Data Type Conversion in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!