Error in converting Cell array to double

2 views (last 30 days)
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 Comment
Stephen23
Stephen23 on 28 Jun 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

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 28 Jun 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

More Answers (0)

Categories

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

Community Treasure Hunt

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

Start Hunting!