Fit multidimensional array into other multidimensional matrix with changing index

4 Ansichten (letzte 30 Tage)
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

Antworten (1)

KALYAN ACHARJYA
KALYAN ACHARJYA am 18 Sep. 2019
Bearbeitet: KALYAN ACHARJYA am 18 Sep. 2019
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 Kommentare
KALYAN ACHARJYA
KALYAN ACHARJYA am 18 Sep. 2019
Bearbeitet: KALYAN ACHARJYA am 18 Sep. 2019
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 am 19 Sep. 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by