필터 지우기
필터 지우기

cell2mat error

조회 수: 3 (최근 30일)
Danielle Leblanc
Danielle Leblanc 2011년 8월 15일
편집: VBBV 2021년 10월 16일
"a" is a 5000x12 cell matrix. all value in "a" are numeric. I tried to convert from cell to double using cell2mat(a) and i received the following error: ??? Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n});
how can I convert this matrix to double?

답변 (3개)

Fangjun Jiang
Fangjun Jiang 2011년 8월 15일
Probably the numeric elements of the cell array are not the same size. See example:
a={1 2;3 4}
b=cell2mat(a)
c={1 2;[3 4] 5}
d=cell2mat(c)

Danielle Leblanc
Danielle Leblanc 2011년 8월 15일
could be but visually i didn't notice anything wrong or similar to the example that you gave. But the number of files is around 3000 and it would be tedious to check the 5000x12 matrix of the 3000 files. I noticed that the number formats are different as well. in one column 3.3 for example and in another 3.3456782.Also there are many empty cells. Do u have any suggestion about how to overcome this problem?
  댓글 수: 1
Fangjun Jiang
Fangjun Jiang 2011년 8월 15일
Is every element supposed to be scalar? Use the following to check the size of each element.
c={1 2;[3 4] 5};
d=cellfun(@size,c,'uni',0);
e=cell2mat(d);
f=all(e==1)

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


Danielle Leblanc
Danielle Leblanc 2011년 8월 15일
I took each column alone and convert it to double using cell2mat. The second column gave the same error ??? Error using ==> cat CAT arguments dimensions are not consistent.
Error in ==> cell2mat at 89 m{n} = cat(1,c{:,n});
I sorted the column and i looked at it carefully.Nothing is strange. All numbers are numbers without decimal points without empty cells,nans,etc.... How come I can 't convert this column to double?
  댓글 수: 1
VBBV
VBBV 2021년 10월 16일
편집: VBBV 2021년 10월 16일
If you are running the code in script, then use clear to clear workspace variables for consistent size of the variables used everytime you run.

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

카테고리

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