Checking parameter value in a function
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Clement Koh
am 8 Nov. 2020
Bearbeitet: Sreeranj Jayadevan
am 11 Nov. 2020
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 Kommentare
Akzeptierte Antwort
Sreeranj Jayadevan
am 11 Nov. 2020
Bearbeitet: Sreeranj Jayadevan
am 11 Nov. 2020
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Ordinary Differential Equations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!