I have a multidimensional matrix

, for example a=[1 2 3 ; 4 5 6 ; 7 8 9] , b=[0 1 3 ; 2 0 4 ; 6 9 8] and c=[2 1 4 ; 5 6 2 ; 4 5 2] , my multidimensional matrix is : d(:,:,1)=a , d(:,:,2)=b and d(:,:,3)=c. now I need the function for adding column or row to d matrix. what is the function???

1 件のコメント

RIZA KAYAALP
RIZA KAYAALP 2017 年 12 月 21 日
for example I want add e=[1 0 ; 0 1 ; 2 2] to all of the pages of d matrix.

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

回答 (2 件)

Star Strider
Star Strider 2017 年 12 月 21 日

0 投票

Try this:
d = cat(3, a, b, c);

2 件のコメント

RIZA KAYAALP
RIZA KAYAALP 2017 年 12 月 21 日
thats not right!!!!!
Star Strider
Star Strider 2017 年 12 月 21 日
Yes it is!!!
You absolutely cannot add (3x2) matrix ‘e’ to a (3x3x3) matrix ‘d’!!!
You have to expand ‘e’ to at least (3x3) to add it. Then you can use bsxfun:
Out = bsxfun(@plus, d,e);

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

Jos (10584)
Jos (10584) 2017 年 12 月 22 日

0 投票

Assuming you have 3D matrix of size N-by-M-by-P and you want to concatenate (I assume you meant this by the word add!) another matrix to one of its dimensions the other dimensions should match!
In your case this cannot be done because d is a 3-by-3-by-3 array, whereas a is 3-by-2! What is the output that you would have expected?
Here is an example
D = randi(10,[3 4 2]) % a 3-by-4-by-2 3D array
E = repmat(-1,[3 2]) % to be added to the 2nd dimension (columns) of D
E2 = reshape(E,[3 1 2])
R = cat(2,D,E2)

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

質問済み:

2017 年 12 月 21 日

回答済み:

2017 年 12 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by