How can I concatenate cell arrays of a cell array into one single column?

580 ビュー (過去 30 日間)
Eric Kudlow
Eric Kudlow 2017 年 8 月 31 日
コメント済み: Syahmeer How 2019 年 2 月 20 日
I have a cell array of data that contains cell arrays of varying length. The number of cells within the cell array will be changing depending on the file I am reading. The data within the cells are characters of varying length. I need to combine all cell arrays within the cell array into one column. I feel like this should be very simple but I have been unable to successfully do it. The code follows:
for i = 1:length(name_cells)
all = name_cells{i,:}(:);
end
This code outputs only the last cell array of course. So when I try this, I get an error message:
for i = 1:length(name_cells)
all(i) = name_cells{i,:}(:);
end
error: Subscripted assignment dimension mismatch.
I realize the indexes don't match being the arrays are of different length, but I don't know of any other way to do this as I am fairly new to Matlab. The data within name_cells looks like this:
'bck2del::kan_whi5del::CaURA3'
Any help would be greatly appreciated.
  1 件のコメント
Jan
Jan 2017 年 8 月 31 日
Describing the input data as text is not really useful. Better post some code which creates an equivalent piece of the data.

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

採用された回答

Jan
Jan 2017 年 8 月 31 日
I guess, how you data look like:
name_cells = {{'a'; 'b'; 'c'}, {'d'}, {'e'; 'f'}};
Then:
nameCol = cat(1, name_cells{:})
creates:
{ 'a'; 'b'; 'c'; 'd'; 'e'; 'f'}
Is this wanted? If not, please post some input and output data.
  2 件のコメント
Eric Kudlow
Eric Kudlow 2017 年 9 月 1 日
Yes that is exactly what I needed. Thank you so much. I can't believe I couldn't figure that out myself.
Syahmeer How
Syahmeer How 2019 年 2 月 20 日
Thanks for the code Jan!!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by