Error in converting Cell array to double
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Mo Ba
el 27 de Jun. de 2017
Comentada: Stephen23
el 28 de Jun. de 2017
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 comentario
Stephen23
el 28 de Jun. de 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
Respuesta aceptada
Stephen23
el 28 de Jun. de 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 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Type Conversion en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!