Fit multidimensional array into other multidimensional matrix with changing index

2 visualizaciones (últimos 30 días)
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

Respuestas (1)

KALYAN ACHARJYA
KALYAN ACHARJYA el 18 de Sept. de 2019
Editada: KALYAN ACHARJYA el 18 de Sept. de 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 comentarios
KALYAN ACHARJYA
KALYAN ACHARJYA el 18 de Sept. de 2019
Editada: KALYAN ACHARJYA el 18 de Sept. de 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 el 19 de Sept. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by