While loop constraint has to be true for every variable

Hello,
I work on a matlab script in which i have an input of 50 parts, numbered 1 to 50. For all of these parts i calculate a specific distribution which gives an attribute to this specific part (the ARF1-value).
In the wile loop, this attribute for every part has to be higher than a target. How can i model that if this attribute is lower than the target, the s-value of this part goes one point higher and if it is higher than the target, this s-value stays the same and this part leaves the while loop? I now have this but it does not work.
Thanks in advance:
while AFR1(i)<TargetAFR;
s=s(i)+1;
for i=1:length(s);
FR(i)=poisscdf(s(i)-1,m(i)*t(i));
AFR1(i)=((m(i)/M)*FR(i));
end
Results(end+1,:) = [iteration:iteration;s;AFR];
iteration = iteration + 1;
end

回答(1 个)

s=s(i)+1;
Is going to overwrite s. Surely you want
s(i) = s(i) + 1
instead.
This line
Results(end+1,:) = [iteration:iteration;s;AFR];
is also suspicious. The first part of that concatenation will always just resolve to 'iteration', though it doesn't do any harm, it's just un-necessary.

2 个评论

Thanks, you're right it has to be s(i)=s(i)+1
However, even when i have this it keeps on iterating forever without reaching the target. The s-values remain zero except for the 50th one, this one goes to infinity..
You need to show more code. I just took a glance at what you posted to find obvious problems, but a second glance shows there are a number of things that don't make sense.
Where is 'i' coming from in your while loop indexing? You are using i lower down as the index for your for loop so don't reuse a variable like that if i is defined higher up. Also if it is you need to include that code because I have no idea what s(i) represents outside of the for loop that loops around i.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

评论:

2016-10-6

Community Treasure Hunt

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

Start Hunting!

Translated by