http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052
MATLAB Central Newsreader  for loop into for loop.
Feed for thread: for loop into for loop.
enus
©19942015 by MathWorks, Inc.
webmaster@mathworks.com
MATLAB Central Newsreader
http://blogs.law.harvard.edu/tech/rss
60
MathWorks
http://www.mathworks.com/images/membrane_icon.gif

Fri, 20 May 2011 09:50:05 +0000
for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837031
zak
Hello this is my first time that i am writing here.. <br>
I need your help to improve my code. This is my code<br>
<br>
for a=1:numberOfShortestPaths<br>
for b=a+1:a+numberOfShortestPaths<br>
for c=b+1:b+numberOfShortestPaths<br>
for d=c+1:c+numberOfShortestPaths<br>
for e=d+1:d+numberOfShortestPaths<br>
total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)+weight(:,:,e);<br>
maximum=max(total_weight);<br>
end<br>
end<br>
end<br>
end<br>
end<br>
<br>
i want to do this function "automatically" because the letters are depending from other parameter(number of calls). in this example the number of calls=5.<br>
if the number=4 the for loops would be until 'd'.. i dont know how to write the code to do this automatic and not manually like that one <br>
Do you have any ideas to recommend me?<br>
Thanks in advance<br>
Zack

Fri, 20 May 2011 11:53:04 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837048
ImageAnalyst
Zack:<br>
I think you need to look into recursive programming.<br>
<br>
The function would call itself. You'd have to pass along the<br>
information as to when the function should "bail out", in other words,<br>
backtrack out or recurse out.

Fri, 20 May 2011 12:18:04 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837055
Andy
"zak " <zaxos_pele@hotmail.com> wrote in message <ir5dgd$12q$1@newscl01ah.mathworks.com>...<br>
> Hello this is my first time that i am writing here.. <br>
> I need your help to improve my code. This is my code<br>
> <br>
> for a=1:numberOfShortestPaths<br>
> for b=a+1:a+numberOfShortestPaths<br>
> for c=b+1:b+numberOfShortestPaths<br>
> for d=c+1:c+numberOfShortestPaths<br>
> for e=d+1:d+numberOfShortestPaths<br>
> total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)+weight(:,:,e);<br>
> maximum=max(total_weight);<br>
> end<br>
> end<br>
> end<br>
> end<br>
> end<br>
> <br>
> i want to do this function "automatically" because the letters are depending from other parameter(number of calls). in this example the number of calls=5.<br>
> if the number=4 the for loops would be until 'd'.. i dont know how to write the code to do this automatic and not manually like that one <br>
> Do you have any ideas to recommend me?<br>
> Thanks in advance<br>
> Zack<br>
<br>
You are overwriting total_weight and maximum inside the loop, therefore losing all of the information except for the final iteration of the loop. I'm guessing this is unintended?

Fri, 20 May 2011 14:49:04 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837086
zak
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <a982d13b9ab74b808b6e18b61a3dcadb@24g2000yqk.googlegroups.com>...<br>
> Zack:<br>
> I think you need to look into recursive programming.<br>
> <br>
> The function would call itself. You'd have to pass along the<br>
> information as to when the function should "bail out", in other words,<br>
> backtrack out or recurse out.<br>
<br>
Hi,thanks for the reply<br>
i know that the solution will come recursively but i am stack in this part, i dont know how to write it.<br>
I would be thankful if you could help me more..

Fri, 20 May 2011 14:57:05 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837088
zak
Hello Andy,<br>
Thanks for the answer.<br>
This is a part of the code.

Fri, 20 May 2011 15:53:46 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837096
ImageAnalyst
On May 20, 10:57 am, "zak " <zaxos_p...@hotmail.com> wrote:<br>
> Hello Andy,<br>
> Thanks for the answer.<br>
> This is a part of the code.<br>
<br>
<br>
We know it's a part of the code, but we were wondering if you really<br>
meant<br>
total_weight=total_weight+weight(:,:,a)+weight(:,:,b)+weight(:,:,c)<br>
+weight(:,:,d)+weight(:,:,e);<br>
instead of<br>
total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)<br>
+weight(:,:,e);<br>
<br>
And you should study up on recursive programming. I can't really give<br>
you a tutorial on it in a newsgroup reply.

Fri, 20 May 2011 16:50:05 +0000
Re: for loop into for loop.
http://www.mathworks.com/matlabcentral/newsreader/view_thread/308052#837105
zak
ImageAnalyst <imageanalyst@mailinator.com> wrote in message <7c722e19520943788cb0cad1d947803f@w21g2000yqm.googlegroups.com>...<br>
> On May 20, 10:57 am, "zak " <zaxos_p...@hotmail.com> wrote:<br>
> > Hello Andy,<br>
> > Thanks for the answer.<br>
> > This is a part of the code.<br>
> <br>
> <br>
> We know it's a part of the code, but we were wondering if you really<br>
> meant<br>
> total_weight=total_weight+weight(:,:,a)+weight(:,:,b)+weight(:,:,c)<br>
> +weight(:,:,d)+weight(:,:,e);<br>
> instead of<br>
> total_weight=weight(:,:,a)+weight(:,:,b)+weight(:,:,c)+weight(:,:,d)<br>
> +weight(:,:,e);<br>
> <br>
> And you should study up on recursive programming. I can't really give<br>
> you a tutorial on it in a newsgroup reply.<br>
<br>
Yes this is what I meant :<br>
total_weight=total_weight+weight(:,:,a)+weight(:,:,b)+weight(:,:,c)<br>
+weight(:,:,d)+weight(:,:,e);<br>
<br>
Thanks for the replies anyway!!