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!