cell2mat error

4 visualizzazioni (ultimi 30 giorni)
Danielle Leblanc
Danielle Leblanc il 15 Ago 2011
Modificato: VBBV il 16 Ott 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?

Risposte (3)

Fangjun Jiang
Fangjun Jiang il 15 Ago 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 il 15 Ago 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 Commento
Fangjun Jiang
Fangjun Jiang il 15 Ago 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)

Accedi per commentare.


Danielle Leblanc
Danielle Leblanc il 15 Ago 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 Commento
VBBV
VBBV il 16 Ott 2021
Modificato: VBBV il 16 Ott 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.

Accedi per commentare.

Categorie

Scopri di più su Data Type Conversion in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by