필터 지우기
필터 지우기

Checking parameter value in a function

조회 수: 2 (최근 30일)
Clement Koh
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 :)

채택된 답변

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