Concatenate rows of cell into one column

7 vues (au cours des 30 derniers jours)
AM
AM le 24 Oct 2018
Hello,
I have one cell A of size nxm and I would like to convert it into a cell of size nx1. For example if
A= { [1] [2] [3] [4] [5]
[6] [7] [8] [9] [10]}
I want
C= { [1 2 3 4 5]
[6 7 8 9 10]}
I tried
for i=1:n
C{i,1} = A{i,:};
end
but this only gives me the first value of A per line
I don't know how to do this, any help is appreciated!

Réponse acceptée

Andrei Bobrov
Andrei Bobrov le 24 Oct 2018
C = cellfun(@cell2mat,num2cell(A,2),'un',0);

Plus de réponses (1)

madhan ravi
madhan ravi le 24 Oct 2018
Modifié(e) : madhan ravi le 24 Oct 2018
A= { [1] [2] [3] [4] [5]
[6] [7] [8] [9] [10]}
c = (cell2mat(A))
C = [{c(1,:)} ;{c(2,:)}]
celldisp(C)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Produits


Version

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by