Convert cell to array

Hi everyone,
I have a cell array 64x1 and I would like to convert in array 64x1, but when I use cell2mat I obatin this result:
180672064x1
Why? How can I resolve this problem?

9 comentarios

Davide Masiello
Davide Masiello el 10 de En. de 2023
Please post you cell array and code.
KSSV
KSSV el 10 de En. de 2023
It looks like your cell array of size 64x1, in there each cell has a array of size 2823001x1. If not you need to provide what is the data and class present in each cell array.
Felicia DE CAPUA
Felicia DE CAPUA el 10 de En. de 2023
You are right, but if I want that this data are grouped together like the cell array, how can I do?
Stephen23
Stephen23 el 10 de En. de 2023
Editada: Stephen23 el 10 de En. de 2023
"if I want that this data are grouped together like the cell array, how can I do?"
Probably the simplest solution is to use a cell array.
Bjorn Gustavsson
Bjorn Gustavsson el 10 de En. de 2023
...or perhaps transpose the cell-array and convert that into what should become a 2-D array:
m2D = cell2mat(c_arra');
The size of m2D should now be something like 2823001 x 64. Perhaps that is what you're after.
Felicia DE CAPUA
Felicia DE CAPUA el 10 de En. de 2023
Sorry, I don't understand. What does 64 mean?
Bjorn Gustavsson
Bjorn Gustavsson el 10 de En. de 2023
64 means sixtyfour. My suggestion would give you one two-million-eighthundred-twentythree-thousand and one by sixtyfour array, that is an array with sixtyfour columns and 2823001 rows.
The reason you get sub-quality answers is that it is not clear what you want to achieve from your question.
Felicia DE CAPUA
Felicia DE CAPUA el 10 de En. de 2023
I have a cell array 64x1, but when I convert this in matrix array I obtain 282301x1. I would like to obtain an array 64x1.
Bjorn Gustavsson
Bjorn Gustavsson el 10 de En. de 2023
Felicia, the elements in your cell-array are themselves arrays, as @KSSV pointed out. When you call cell2mat the contents of the cells are merged, if that is possible, into one array. For this to work the sizes of the elements have to match the right way. For your case, you can check what sizes the cells-contents are by simply typing the name of the cell-array variable at the command-line prompt.
For your expressed objective to make sense you will need to decide which element of each cell you want to extract into your ordinary array. If it for example is the second component in each element you can do something like this:
for i1 = 64:-1:1
a_regular(i1) = cell_variable{i1}(1);
end

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Productos

Preguntada:

el 10 de En. de 2023

Comentada:

el 10 de En. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by