Checking parameter value in a function
5 ビュー (過去 30 日間)
古いコメントを表示
Clement Koh
2020 年 11 月 8 日
編集済み: Sreeranj Jayadevan
2020 年 11 月 11 日
Hi all!
Suppose I have a few parameters in a function file of ODEs. And given that I have set a parameter (for e.g 'Var_A') to change according to time. Are there any ways that I can retrieve the value of the parameter over a period of time and plot them? I just want to show that the parameter change over a period of time.
Pls advise whoever knows this. Thank you :)
0 件のコメント
採用された回答
Sreeranj Jayadevan
2020 年 11 月 11 日
編集済み: Sreeranj Jayadevan
2020 年 11 月 11 日
An easy way to achieve this is to create a scalar variable and then to gradually increase the size over time while you execute the code. For example, if you wish to store the value of 'Var_A' after each iteration (with respect to time in this case) you can concatenate the new values over time and create a 1-D array. i,e
Arr=0;
for i=1:n
% Various operations your function performs. Var_A gets updated here
Arr(i)=Var_A;
end
'Arr' will contain the required values which you can plot with respect to time.
Note: This approach is however not recommended if 'n' is a large value as this leads to repeated reallocation of memory by MATLAB. You can go through the following link for more information: https://in.mathworks.com/help/matlab/matlab_prog/preallocating-arrays.html
A alternative method which is more efficient would be to initialize the array/vector beforehand and populating the initialized array during execution. If you know how many elements the vector will contain after execution, you can initialize the vector.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!