Calculation between 2 vectors where one is 4d and other is 1d

조회 수: 2 (최근 30일)
Saugata Bose
Saugata Bose 2019년 5월 28일
편집: Raghunandan V 2019년 5월 28일
Dear,
I have 2 vectors. One is of 4d form and other is of 1d form. The value of one vector will be subtracted from the values of the othe vector.
Example:
A=[val(:,:,1,1)
= 0.67
val(:,:,2,1)
=0.55
val(:,:,3,1)
=0.12
val(:,:,1,2)
= 0.12
val(:,:,2,2)
=0.50
val(:,:,3,2)
=0.11
]
B=[1
0]
The operation would be like this one
Result=[
val(:,:,1,1) =0.67-1
val(:,:,2,1) =0.55-1
val(:,:,3,1) =0.12-1
val(:,:,1,2) =0.12-0
val(:,:,2,2) =0.5-0
val(:,:,3,2) =0.11-0
]
Would you please help me calculating this?
thanks,

답변 (1개)

Raghunandan V
Raghunandan V 2019년 5월 28일
편집: Raghunandan V 2019년 5월 28일
Hi,
small explanation of How I approached the answer. I changed domenstion on B so that it would that of A and the subtracted them both
A = zeros(5,5, 3,2) ;%assumed Dimensions
%value storing
A(:,:,1,1)= 0.67;
A(:,:,2,1)= 0.55;
A(:,:,3,1)= 0.12;
A(:,:,1,2)= 0.12;
A(:,:,2,2)= 0.5;
A(:,:,3,2)= 0.11;
B = [1 ;0];
%get dimenstions of A
[m n o p ] = size(A);
%create two temporary matrices
R1 = B(1)*ones(m,n,o);
R2 = B(2)*ones(m,n,o);
%here multiplication is used to make it versatile for any value of B
%initialize new B
NewB = zeros(m,n,o,p);
NewB(:,:,:,1)= R1;
NewB(:,:,:,2)= R2;
result = A - NewB;
  댓글 수: 1
Saugata Bose
Saugata Bose 2019년 5월 28일
@Raghunandan V: thanks fr ur help. i m giving you the feedback after implementing it in my main code.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by