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!