Fit multidimensional array into other multidimensional matrix with changing index

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by