Converting a cell array containing more cell arrays to one cell matrix

22 ビュー (過去 30 日間)
Patrick Comiskey
Patrick Comiskey 2016 年 2 月 8 日
コメント済み: Patrick Comiskey 2016 年 2 月 8 日
Hello,
This is a disturbingly simple process that I'm having the hardest time with and I can't seem to find out how to do it from other online sources or help files. I've got a cell array, C, which contains other cell arrays (a mix between numeric data and strings) and I'm trying to "break" the contained cells to combine into one cell matrix. For example:
C=
{1x4 cell}
{1x4 cell}
{1x4 cell}
How do I break apart C to get the contents into a cell matrix of size 1x11? The result should look like:
A=
[2013] 'January' [7] 'S1.13'
[2013] 'October' [5] 'S8.13'
[2014] 'June' [8] 'S6.14'
  1 件のコメント
Guillaume
Guillaume 2016 年 2 月 8 日
A looks like a cell array of size 3x4. I don't see how you'd get a 1x11 array out of a cell array with 12 elements.

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

採用された回答

Guillaume
Guillaume 2016 年 2 月 8 日
If all the subcells are the same size, it's very simple to obtain your A (3x4 cell array)
C = {{[2013] 'January' [7] 'S1.13'}; {[2013] 'October' [5] 'S8.13'}; {[2014] 'June' [8] 'S6.14'}};
A = vertcat(C{:})
If they are not the same size but all row vectors, you can concatenate them horizontally instead (so A is 1x12 in this case):
A = horzcat(C{:}) %can simply be written [C{:}]
If they're all different shape, it of course cannot be done without reshaping the subcells.
  1 件のコメント
Patrick Comiskey
Patrick Comiskey 2016 年 2 月 8 日
vertcat worked perfectly. I knew it was simple but just couldn't think of it, thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by