cell2mat error

3 views (last 30 days)
Danielle Leblanc
Danielle Leblanc on 15 Aug 2011
Edited: VBBV on 16 Oct 2021
"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?

Answers (3)

Fangjun Jiang
Fangjun Jiang on 15 Aug 2011
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 on 15 Aug 2011
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 Comment
Fangjun Jiang
Fangjun Jiang on 15 Aug 2011
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)

Sign in to comment.


Danielle Leblanc
Danielle Leblanc on 15 Aug 2011
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 Comment
VBBV
VBBV on 16 Oct 2021
Edited: VBBV on 16 Oct 2021
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.

Sign in to comment.

Categories

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

Tags

Community Treasure Hunt

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

Start Hunting!