Extracting data from a loop
1 次查看(过去 30 天)
显示 更早的评论
(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
2011-3-6
Please reformat your pseudo code. It would be a very good idea to post Matlab code instead.
回答(4 个)
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
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
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.
0 个评论
Paulo Silva
2011-3-6
function Sactual = Untitled(P,Cactual)
for Sactual=0:10
Ccalculated=S*P;
if Ccalculated~=Cactual, break,end
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!