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 件のコメント
Benjamin Azrieli
Benjamin Azrieli 2020 年 11 月 11 日
Perfect, thank you!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeData Type Conversion についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by