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

1 visualización (últimos 30 días)
Saugata Bose
Saugata Bose el 28 de Mayo de 2019
Editada: Raghunandan V el 28 de Mayo de 2019
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,

Respuestas (1)

Raghunandan V
Raghunandan V el 28 de Mayo de 2019
Editada: Raghunandan V el 28 de Mayo de 2019
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 comentario
Saugata Bose
Saugata Bose el 28 de Mayo de 2019
@Raghunandan V: thanks fr ur help. i m giving you the feedback after implementing it in my main code.

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by