loop executing more then the given iteration.
조회 수: 9 (최근 30일)
이전 댓글 표시
i am calling one function inside the loop,in 1st iteration function calling and returning gud result,but when i have given more then one iteration(more then one function call),i am getting multiple result,loop should run only two time ,but its running three times.
it is because of function call inside the loop.
for y=1:count1 result(1)=comb(1); switch(y) case 1 for z=1:2 result(y+1)=acid(z); index=y+1; funcomb(index,result,acid); end end % switch end end
Any solution to this problem ?
댓글 수: 0
답변 (3개)
Amit
2013년 12월 27일
There are 2 loops. Loop y and loop z.
The only time switch is activating is for y = 1 ( I dont understand the purpose of that for y=1:count1 loop??) Inside the case 1, the loop is running twice however both times it is doing the same thing as they are are related to outer loop index, which will remain 1.
Can you post you results where you having trouble? That might help. And a little explanation of the purpose - I am only asking because it seems from this code that the loops are unnecessary here.
댓글 수: 0
Amit
2013년 12월 28일
편집: Amit
2013년 12월 28일
This might be a little help for what you trying to do.
To be honest, I am a bit confused looking at your code. I am trying to justify the for loop along with switch? The switch only evaluates the first time in the loop and does not do anything afterwards.
Also, am I correct in saying that from a [L/M-A-A-A-A-A-Y-A-A-A-A-A-K/N] expression, with A = [A B C D E], you want sequences where the second term is A and the 3 term is Y and last term is K? [LAYAK], [LAYABK] etc etc?
댓글 수: 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!