How do I find which element of the matrix was used for this equation?

2 ビュー (過去 30 日間)
Lets say I have 2 single column matrices u16 and uexact16. They both have the same number of elements (i). I need to solve the following equation :
e = max(abs(u16(i) - uexact16(i)) / uexact16(i)
The problem is that after I find the maximum difference (by creating a matrix with all the differences), I don't know how to call which uexact16(i) was used in order to divide with it.
for i = 1:17
absDifference(i) = abs(u16(i) - uexact16(i));
end
emax = (max(absDifference'))/ ????

採用された回答

Marco Riani
Marco Riani 2021 年 4 月 1 日
Hi, just call max with two output arguments
Please let me know if rowWithMaximumDifference below is what you want
Best wishes
Marco
n=10;
u16=randn(n,1);
uexact16=randn(n,1);
[~,rowWithMaximumDifference]=max(abs(u16-uexact16))
  1 件のコメント
Konstantinos Angelos Maskalaris
Konstantinos Angelos Maskalaris 2021 年 4 月 1 日
Yes that's exactly it thank you !!!
[M,I] = max(absDifference');
This way M = max value and I = "position of said value on the matrix". After that all I had to do was divide by uexact16(I)
Thank you for the response

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

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by