필터 지우기
필터 지우기

Extracting data from a loop

조회 수: 1 (최근 30일)
Jason
Jason 2011년 3월 6일
(pseudocode)
function Sactual = Untitled( P,Cactual)
% Ccalculated = The calculated sand concentration from the loop % Cactual = The known sand concentration from the loop
S=0:1:10;
A loop that stops looping when Ccalculated ~= Cactual Ccalculated = S*P; end
Extract the last value calculated to get Sactual
end
Is there a way of extracting the last calculated value. So for example if P=2 and Cactual = 6 the value of Sactual should be 3.
Also is there a loop that stops looping when Ccalculated ~= Cactual? I imagine using the while function only stops for one loop and keep iterating the rest
  댓글 수: 1
Jan
Jan 2011년 3월 6일
Please reformat your pseudo code. It would be a very good idea to post Matlab code instead.

댓글을 달려면 로그인하십시오.

답변 (4개)

Jan
Jan 2011년 3월 6일
Getting the last calculated value is trivial: Ccalculated is this value already.
If the inner loop should stop, when Ccalulated differs from Cactual, there is no reason to stop the outer loop.
Summary: I do not understand, what you are trying to achieve. Please formulate the question with more details.
  댓글 수: 1
Paulo Silva
Paulo Silva 2011년 3월 6일
neither do I but what can we do when people don't take their time to think about what they are asking, at least Jason tried to come up with pseudo pseudo code lol
there are people that don't even explain what they want!

댓글을 달려면 로그인하십시오.


Jan
Jan 2011년 3월 6일
Or perhaps:
function Sactual = Untitled(P, Cactual)
Sactual = find((0:10) * P == Cactual) - 1;
Actually I do not see a need for a loop at all. Even "round(Cactual / P) - 1" might be a valid solution.
But let's wait and see if Jason can enlighten us.

Paulo Silva
Paulo Silva 2011년 3월 6일
function Sactual = Untitled(P,Cactual)
for Sactual=0:10
Ccalculated=S*P;
if Ccalculated~=Cactual, break,end
end

Jason
Jason 2011년 3월 6일
Hey sorry I didn't really explain what I'm doing with much clarity. This is an overview of the problem I'm trying to solve. This equation finds the minimum stream power of a river. 1. Assume a value for D. 2. Work out V from V=Q/(W*D) (values Q,W are inputted) 3. Solve S=(w*Cts*10^(I/J))/(V-Vcr) Where: I = 5.435-0.286*log10(w*d/v)-0.457*log10(Us/w) J = 1.799-0.409*log10(w*d/v)-0.314*log10(Us/w)
Us = (9.81*R*S)^0.5;
if Us*d/v is between 1.2 and 70
Vcr=w*((2.5/(log10(Us*d/v)-0.06))+0.66)
Otherwise
Vcr=w*2.05
So Us and as a result I and J depend on S
4. Select another D and repeat the steps 5. Compare computed V*S values and find a minimum value
So I have two equations and three unknowns. I thought the best way of solving this is by rearranging the equation in point no.3 to have Cts = function(...) instead of S = function(...). Then iterate to find S when the computed Cts equals the Cts inputted at the start of the function. Cts=Cactual. The inputs would be Cactual,Cts,R,d,v,w,Q,W,D
I'm not very good at explaining things but I hope this sheds some light on the situation. Thanks for the help you've already given me :)
  댓글 수: 1
Paulo Silva
Paulo Silva 2011년 3월 6일
That almost doesn't seem related to the original question!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by