IF statement to fill a cell array base on conditions
3 次查看(过去 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!