Concatenate nested cell array in one

Hello matlab community,
how do I concatenate arrays with different sizes into one dimensional array:
Example
dblArrayX{1}{1} = [12;15];
dblArrayX{2}{1} = 13;
dblArrayX{3}{1} = [16;17;19];
unknown method leads to
newArray{1} = [12;15;13;16;17;19]
I need the method for this newArray without loops.

6 件のコメント

Mate D
Mate D 2020 年 5 月 26 日
編集済み: Mate D 2020 年 5 月 26 日
My approach works but I need this in one line without temporary variable x:
x = cellfun(@(Y)Y(1),dblArrayX);
newArray{1} = vertcat(x{:});
Stephen23
Stephen23 2020 年 5 月 26 日
"Concatenate multi dim array..."
None of your arrays are "multi dim".
Mate D
Mate D 2020 年 5 月 26 日
Ohh sorry for missleading topic name ... Thought it is multidimensional since the array runs over {y} and {x} afterwards and it contains itself double with size (z,1). What would be the proper name of this kind of array ?
Stephen23
Stephen23 2020 年 5 月 26 日
編集済み: Stephen23 2020 年 5 月 26 日
Nested cell arrays: your examples shows a cell array that contains cell arrays that contain other arrays. That is nesting.
You usage of "multi dim" for nested cell arrays sounds a bit like some other languages which have to resort to nesting of lists to try and mimic any kind of matrix or ND array, but MATLAB natively supports actual ND arrays:
Rik
Rik 2020 年 5 月 26 日
Can you edit your question so it contains the actual shape of your data?
Mate D
Mate D 2020 年 5 月 28 日
編集済み: Mate D 2020 年 5 月 28 日
The data is in exact format as the example. Do not know why, but it works with the method you presented (and deleted) earlier:
cell2mat(cellfun(@(X) X{1},tmpMdlParamsValues','UniformOutput',false))

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

 採用された回答

Rik
Rik 2020 年 5 月 28 日

0 投票

Since apparently it was the correct solution, I'll repost it:
It puzzles me why you would want this without the temporary variable. Putting it on one line is of course trivial. The code below should do what you need.
newArray{1}=cell2mat(cellfun(@(x) x{1},dblArrayX','UniformOutput',false));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2020 年 5 月 26 日

回答済み:

Rik
2020 年 5 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by