Extracting data from a loop

3 views (last 30 days)
Jason
Jason on 6 Mar 2011
(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 Comment
Jan
Jan on 6 Mar 2011
Please reformat your pseudo code. It would be a very good idea to post Matlab code instead.

Sign in to comment.

Answers (4)

Jan
Jan on 6 Mar 2011
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 Comment
Paulo Silva
Paulo Silva on 6 Mar 2011
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!

Sign in to comment.


Jan
Jan on 6 Mar 2011
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 on 6 Mar 2011
function Sactual = Untitled(P,Cactual)
for Sactual=0:10
Ccalculated=S*P;
if Ccalculated~=Cactual, break,end
end

Jason
Jason on 6 Mar 2011
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 Comment
Paulo Silva
Paulo Silva on 6 Mar 2011
That almost doesn't seem related to the original question!

Sign in to comment.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!