How to change the variable value while looping and plotting ode in a .m file?

1 回表示 (過去 30 日間)
Yen Min Chew
Yen Min Chew 2021 年 6 月 25 日
回答済み: Ashutosh Singh Baghel 2021 年 8 月 31 日
I am looping and plotting two ode equations to show live graph, however, I need to change the value of variables while running my program files (.m file). I try to use if instruction but I found that the new value I input was not updated in the graphs. Any suggestion to solve this issue without using GUI? I use this code below my plotting in a for loop.
Change = input('Change? ');
if Change==1
A = input('Enter new A: ' );
elseif Change==2
B = input('Enter new B: ' );
else
end
  1 件のコメント
Scott MacKenzie
Scott MacKenzie 2021 年 6 月 25 日
編集済み: Scott MacKenzie 2021 年 6 月 25 日
The problem you note (the new value I input was not updated in the graphs) is not related to the code in your question. If the user enters "1" for the 1st prompt then, say, "33" for the 2nd prompt, the variable A is assigned the inputed value (33) and the value of B is unchanged. I assume that is what you want. If not, try to clarify the desired behaviour.

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

回答 (1 件)

Ashutosh Singh Baghel
Ashutosh Singh Baghel 2021 年 8 月 31 日
Hi Yen,
I understand you wish to update values of 'A' or 'B' everytime '.m' file is executed. with the problem you stated - "the new value I input was not updated in the graphs", please find an alternate approach to achieve this without 'if-else' statement.
Change = input('Change? ');
switch(Change)
case 1
A = input('Enter new A: ');
case 2
B = input('Enter new B: ');
otherwise
display('invalid option');
end

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by