I want to run a loop until a value is reached and, then, I want to use that reached value to continue the loop

76 次查看(过去 30 天)
Hi everyone! Thanks for helping.
I'm running a code about hydrogeology. I'm calculating tha saturated portion of a soil depending on rainfall amount.
I need Matlab to calculate this saturated thickness until a certain value H is reached. This value is the maximum depth of the soil of course.
When the loop reaches H, I want Matlab to keep on doing the calculations assuming H as the new starting point, instead of the value > H that it has been encountered.
How can I do this? Thanks for helping!

采纳的回答

Voss
Voss 2022-4-13
Hard to say for sure, but maybe some structure like this (but with a break condition - which was unspecified in the question):
H = 100;
thickness = 0;
while true
thickness = thickness+1;
if thickness >= H
thickness = thickness-H;
end
end

更多回答(1 个)

jjjSAN
jjjSAN 2022-4-14
Many many thanks!! Finally I managed by doing this:
ii = 1;
m(1) = m0;
deltam(1) = 0;
output(1) = 0;
while true
ii = ii + 1
output(ii) = prod*m(ii-1);
deltam(ii) = ((input(ii)-output(ii))./den2(ii));
m(ii) = (m(ii-1) + deltam(ii));
if m(ii) >= H;
m(ii) = H;
end
end
  4 个评论
jjjSAN
jjjSAN 2022-4-14
Finally I just added an if loop inside the code I posted earlier:
if ii > a (a was the length of my dataset)
break
end
And so it runs normally now :D

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Measurements and Spatial Audio 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by