Effacer les filtres
Effacer les filtres

Convert cell to array

3 vues (au cours des 30 derniers jours)
Felicia DE CAPUA
Felicia DE CAPUA le 10 Jan 2023
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 commentaires
Felicia DE CAPUA
Felicia DE CAPUA le 10 Jan 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 le 10 Jan 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

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by