Checking parameter value in a function

7 次查看(过去 30 天)
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 :)

采纳的回答

Sreeranj Jayadevan
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 个)

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by