Calculation between 2 vectors where one is 4d and other is 1d
1 次查看(过去 30 天)
显示 更早的评论
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,
0 个评论
回答(1 个)
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;
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Subplots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!