Fit multidimensional array into other multidimensional matrix with changing index

1 回表示 (過去 30 日間)
Pascal Loohuis
Pascal Loohuis 2019 年 9 月 18 日
コメント済み: Pascal Loohuis 2019 年 9 月 19 日
Hi!
Let's say you have the matrix A= 4 x 4 x 2 and B=2 x 2 x 2. I want for A(:,:,1) to paste B(:,:,1)=[1 1; 1 1] onto A(:,:,1) such that
A(:,:,1)=[ 1 1 0 0;
1 1 0 0;
0 0 0 0;
0 0 0 0]
and I want for A(:,:,2) to paste B(:,:,2)=[2 2; 2 2] onto A(:,:,2) such that
A(:,:,1)=[ 0 0 0 0;
0 0 0 0;
0 0 2 2;
0 0 2 2]
without using a for loop. Is this possible?
Kind regards,
Pascal

回答 (1 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 18 日
Suppose, as per your question, considering random A and B
A=rand(4,4,2);
B=rand(2,2,2);
Now you want for A(:,:,1) to paste B(:,:,1)
Let's see
>>A(:,:,1)
0.4387 0.1869 0.7094 0.6551
0.3816 0.4898 0.7547 0.1626
0.7655 0.4456 0.2760 0.1190
0.7952 0.6463 0.6797 0.4984
A(:,:,1) is having size 4x4 and
>>B(:,:,1)
0.8143 0.9293
0.2435 0.3500
B(:,:,1) is having size 2x2
How do you going to replace?
  3 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 18 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 18 日
certain values will be replaced by the values of B
Just an example:
>>A(:,:,1)
0.4387 0.1869 0.7094 0.6551
0.3816 0.4898 0.7547 0.1626
0.7655 0.4456 0.2760 0.1190
0.7952 0.6463 0.6797 0.4984
and
>>B(:,:,1)
0.8143 0.9293
0.2435 0.3500
Now you can replace the B(:,:,1) in any quadrant of A(:,:,1) ; 2x 2 area??
Is this??
Pascal Loohuis
Pascal Loohuis 2019 年 9 月 19 日
That's right. But I want to extend it to a multidimensional A and B. Whereby the different 2 by 2 matrices of B are placed on different positions within matrices of A.

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

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by