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

1 回表示 (過去 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 Center および File ExchangeSubplots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by