フィルターのクリア

Concantenate Horizontally Matrices from Two Different Cell Arrays

1 回表示 (過去 30 日間)
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2017 年 9 月 11 日
編集済み: Konstantinos Tsitsilonis 2017 年 9 月 11 日
Hi all,
I have two cell arrays as follows:
A = { [1; 2; 3; 4], [5; 6; 7; 8] } ;
B = { [9; 10; 11; 12], [13; 14; 15; 16] } ;
I would like to create a new cell array such that:
C = { [1 9 ; 2 10 ; 3 11 ; 4 12], [5 13 ; 6 14 ; 7 15 ; 8 16]} ;
In words, I would like to concatenate horizontally the matrices in each cell of the cell array.
Is there a way to do that?
Thanks for your help in advance,
KMT

採用された回答

Guillaume
Guillaume 2017 年 9 月 11 日
編集済み: Guillaume 2017 年 9 月 11 日
You say concatenate horizontally, yet your example show vertical concatenation
cellfun(@vertcat, A, B, 'UniformOutput', false)
replace vertcat by horzcat as required.
  1 件のコメント
Konstantinos Tsitsilonis
Konstantinos Tsitsilonis 2017 年 9 月 11 日
編集済み: Konstantinos Tsitsilonis 2017 年 9 月 11 日
Sorry for the confusion, I have corrected my question. I do understand the underlying logic of your function. Thanks for your answer!

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

その他の回答 (1 件)

KL
KL 2017 年 9 月 11 日
Assuming your matrix dimensions are consistent,
cellfun(@(a,b) [a;b],A,B,'UniformOutput',false)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by