IF statement to fill a cell array base on conditions
조회 수: 1 (최근 30일)
이전 댓글 표시
I have an ODE function with time dependent variables, one of the time dependent variable I am trying to pass throug the equation is volume. I want to set a an if statement that will fill a cell array that contains volume change over time. What I am have trouble with is writing the proper if statement.
My goal is to change volume for a certain amount of time, in my case I am changing volume until I meet a threshold, then stay constant at that threshold for another prescribed time, then when I crossed a certain depth I want to change volume again until I meet the seond threshold. Once I create this cell array, I wan to pass it to my function.
Here is my code:
DEPTH=y(1);
%% Calculating Displaced Volume as a function of flowrate and time
%cubic meter
VBD_State=cell(length(time),1);
pumprate=23.3/1000000;
total_oil=2600/1000000;
new_total_oil=1300;
for b = 1:length(time)
if displaced_volume(time(b),pumprate)<=total_oil
VBD_State{b,1}=displaced_volume(time(b),pumprate);
end
if DEPTH ==900 && displaced_volume(time(c),pumprate)<=new_total_oil
VBD_State{b,1}=displaced_volume(time(c),pumprate);
else
VBD_State{(b),1}=total_oil;
end
end
end
댓글 수: 0
답변 (2개)
Ayush Gupta
2020년 9월 2일
Let’s say the two-volume threshold are volume_threshold1 and volume_threshold2, it can be done like this. Refer to the following code:
if(depth < depth_threshold)
if(current_volume < volume_threshold1)
change volume or do whtatever
end
else
if(current volume < colume_threshold2)
change the volume accordingly
end
end
And change the symbols accordingly to fit it.
댓글 수: 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!