While loop constraint has to be true for every variable
Show older comments
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
Answers (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 Comments
Sophie TU/e
on 6 Oct 2016
Adam
on 6 Oct 2016
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.
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!