Error in converting Cell array to double

조회 수: 1 (최근 30일)
Mo Ba
Mo Ba 2017년 6월 27일
댓글: Stephen23 2017년 6월 28일
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
Stephen23
Stephen23 2017년 6월 28일
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

댓글을 달려면 로그인하십시오.

채택된 답변

Stephen23
Stephen23 2017년 6월 28일
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개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by