cell2mat error

4 次查看(过去 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