Finding the x correspondent of of the max y, in a loop.

1 回表示 (過去 30 日間)
A Tex
A Tex 2021 年 2 月 19 日
編集済み: A Tex 2021 年 3 月 1 日
So I currently have a loop in a loop and with the inside loop I use to populate a zeros array, Q, and the outer loop I use to change a value which will give me a different Q array each time. But for each Q, I need to find its max value and corresponding x value ( from vmax). The issue is, it seems my loops are fine, but for each loop, it does not change the value for vmax(index) and neither the max(Q) value. This is evident as just before the end of the inside loop I set vmax(index) to 0 and through the rest of the program it stayed at 0.
TT = zeros(9,1) %Vcrit
PP = zeros(9,1) % DAF
for aa = 0:8
% static analysis
a = a1 + aa*0.2
Q= zeros(79,1);
%% an ODE is present here
for ii = 0:78
%% an ODE is present here
Q(ii+1) = Rdyn/Rstatic;
Qmax = max(Q)
[Q_max, index] = max(Q);
vmax_max = vmax(index)
end
TT(aa+1) = vmax(index)
PP(aa+1) = max(Q)
end

回答 (1 件)

Gaurav Garg
Gaurav Garg 2021 年 2 月 22 日
Hi,
Assuming that you have initialized the vmax array before the provided source code, vmax array has not been updated in the given piece of code at any point.However, you are finding max(Q) correctly by assigning the index of maximum value and maximum value.
  1 件のコメント
A Tex
A Tex 2021 年 3 月 1 日
編集済み: A Tex 2021 年 3 月 1 日
How do I update the vmax array?
Thanks.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by