Extracting data from a loop
3 views (last 30 days)
Show older comments
(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
on 6 Mar 2011
Please reformat your pseudo code. It would be a very good idea to post Matlab code instead.
Answers (4)
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
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!
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.
0 Comments
Paulo Silva
on 6 Mar 2011
function Sactual = Untitled(P,Cactual)
for Sactual=0:10
Ccalculated=S*P;
if Ccalculated~=Cactual, break,end
end
0 Comments
See Also
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!