Substract Each Element in A Matrix MAT1 from all the elements of another Matrix MAT2

1 回表示 (過去 30 日間)
Tareq Rahmani
Tareq Rahmani 2020 年 3 月 28 日
コメント済み: Tareq Rahmani 2020 年 3 月 28 日
Hi MATLAB experts ,
I have a matrix MAT1:
a1 x1 y1
b2 x2 y2
c3 x3 y3
and MATRIX MAT2 :
k1 z1
k2 z2
k3 z3
I want to do : (abs(x1-k1)+abs(y1-z1)) * (abs(x1-k2)+abs(y1-z2)) * (abs(x1-k3)+abs(y1-z3)) * ....etc
this is for every row of MAT1
Thanks very much

回答 (1 件)

Peng Li
Peng Li 2020 年 3 月 28 日
What MATLAB version are you using?
Newer versions actually support operations between e.g. a vector and a 2-d matrix if they have one dimension of the same length.
For your question, an easier work around is
k = 1;
prod(sum(mat1(k, 2:end) + mat2, 2));
you can make above code in loop to run through all rows. Should be ways to avoid this loop too.
  1 件のコメント
Tareq Rahmani
Tareq Rahmani 2020 年 3 月 28 日
Thanks very much . But, I want it without using any loop.
I want some matrix operations that lead to the result.
Because , I think using matrices directly exceutes faster than looping in case of huge data

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by