hi
I want to set an if loop within for loops
My idea is if the constraint satified then stop the for (j) loop and profit (i,j) does not exist; otherwise continue the loop and find the solution
but my code doesnt work well: it cannot stop the for loop when the if loop is satisfied
for i=1:numel(k)
for j=1:numel(lambda)
if lambda(j)/(mu*k(i)) >= 1
return
else
n = (0:(k(i)-1));
W = 1/(sum((a).^n./factorial(n))+a^k(i)/(factorial(k(i))*(1-a/k(i))));
profit(i,j) = lambda(j)*(p-w);
end
end
end

 채택된 답변

KSSV
KSSV 2017년 5월 9일

0 개 추천

Replace return with break.

댓글 수: 5

Luna
Luna 2017년 5월 9일
yes thanks using break makes the corresponding profit(i,j) equal to zero but I want to set the value does not exist do you have any method??
Thanks a lot!!
KSSV
KSSV 2017년 5월 9일
but I want to set the value does not exist not clear..what value you want to set?
Luna
Luna 2017년 5월 9일
I mean no value... I want to set if the constraint is satisfied the corrreponding point does not exist
You can initialize profit to a NaN matrix. Where ever it is not calculated you will get NaN.
profit = NaN(numel(k),numel(lambda)) ;
Luna
Luna 2017년 5월 9일
it works. thanks!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2017년 5월 9일

댓글:

2017년 5월 9일

Community Treasure Hunt

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

Start Hunting!

Translated by