Concatenate rows of cell into one column

조회 수: 7 (최근 30일)
AM
AM 2018년 10월 24일
댓글: Benjamin Azrieli 2020년 11월 11일
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!

채택된 답변

Andrei Bobrov
Andrei Bobrov 2018년 10월 24일
C = cellfun(@cell2mat,num2cell(A,2),'un',0);

추가 답변 (1개)

madhan ravi
madhan ravi 2018년 10월 24일
편집: madhan ravi 2018년 10월 24일
A= { [1] [2] [3] [4] [5]
[6] [7] [8] [9] [10]}
c = (cell2mat(A))
C = [{c(1,:)} ;{c(2,:)}]
celldisp(C)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by