http://www.mathworks.com/matlabcentral/newsreader/view_thread/287101
MATLAB Central Newsreader  avoid for
Feed for thread: avoid for
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, 16 Jul 2010 18:04:51 +0000
avoid for
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287101#763217
Blue gRay
Hi,<br>
<br>
I have a matrix X [m x n] and a vector Y [m x 1]<br>
<br>
I want to update X following this algorithm<br>
<br>
for i=1:m<br>
for j=1:m<br>
if Y(j)<Y(i)<br>
rj = sqrt(sum((X(i,:)X(j,:)).^2));<br>
B = rj*coeff;<br>
X(i,:) = (1B)*X(i,:) + B*X(j,:) + ui(iter,:);<br>
end<br>
end<br>
end<br>
<br>
A professor said me that there is a possibility to avoid the 2 cycles and <br>
make it just by matrix operations (not exactly that algorithm but similar, <br>
by considering the coefficient B in the (1B)*X(i,:) like the mean of all <br>
the B for the j that satify Y(j)<Y(i) )<br>
<br>
I am trying to figure out how to do that but without success.<br>
Do someone see some tricky solution for it?<br>
<br>
Cheers<br>
<br>
fff<br>
<br>
<br>
<br>
<br>
 news://freenews.netfront.net/  complaints: news@netfront.net 

Fri, 16 Jul 2010 20:47:05 +0000
Re: avoid for
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287101#763258
Travis Knepp
"Blue gRay" <ffffffffffffffff@hotmail.com> wrote in message <i1q705$2egd$1@adenine.netfront.net>...<br>
> Hi,<br>
> <br>
> I have a matrix X [m x n] and a vector Y [m x 1]<br>
> <br>
> I want to update X following this algorithm<br>
> <br>
> for i=1:m<br>
> for j=1:m<br>
> if Y(j)<Y(i)<br>
> rj = sqrt(sum((X(i,:)X(j,:)).^2));<br>
> B = rj*coeff;<br>
> X(i,:) = (1B)*X(i,:) + B*X(j,:) + ui(iter,:);<br>
> end<br>
> end<br>
> end<br>
> <br>
> A professor said me that there is a possibility to avoid the 2 cycles and <br>
> make it just by matrix operations (not exactly that algorithm but similar, <br>
> by considering the coefficient B in the (1B)*X(i,:) like the mean of all <br>
> the B for the j that satify Y(j)<Y(i) )<br>
> <br>
> I am trying to figure out how to do that but without success.<br>
> Do someone see some tricky solution for it?<br>
> <br>
> Cheers<br>
> <br>
> fff<br>
> <br>
> <br>
> <br>
> <br>
>  news://freenews.netfront.net/  complaints: news@netfront.net <br>
<br>
<br>
What is it, exactly, that you are trying to do? I'm having a hard time following the script you provided to determine what the overall goal is. That may be useful to know.

Fri, 16 Jul 2010 21:19:04 +0000
Re: avoid for
http://www.mathworks.com/matlabcentral/newsreader/view_thread/287101#763274
Roger Stafford
"Blue gRay" <ffffffffffffffff@hotmail.com> wrote in message <i1q705$2egd$1@adenine.netfront.net>...<br>
> Hi,<br>
> <br>
> I have a matrix X [m x n] and a vector Y [m x 1]<br>
> <br>
> I want to update X following this algorithm<br>
> <br>
> for i=1:m<br>
> for j=1:m<br>
> if Y(j)<Y(i)<br>
> rj = sqrt(sum((X(i,:)X(j,:)).^2));<br>
> B = rj*coeff;<br>
> X(i,:) = (1B)*X(i,:) + B*X(j,:) + ui(iter,:);<br>
> end<br>
> end<br>
> end<br>
> <br>
> A professor said me that there is a possibility to avoid the 2 cycles and <br>
> make it just by matrix operations (not exactly that algorithm but similar, <br>
> by considering the coefficient B in the (1B)*X(i,:) like the mean of all <br>
> the B for the j that satify Y(j)<Y(i) )<br>
> <br>
> I am trying to figure out how to do that but without success.<br>
> Do someone see some tricky solution for it?<br>
> <br>
> Cheers<br>
> fff<br>
        <br>
I think as it stands your results in X will in general depend on the order in which the i and j indices are processed. If you wrote "for j=m:1:1" or "for i=m:1:1" for example with everything else the same, you should get different results. This is not due solely to the variability of B. It is the order in which the "averaging" actions are performed on X that matters too. In other words there is no "commutative" law in place here  order matters.<br>
<br>
It seems a strange way of "updating" X. I suspect that your double loop method is very likely the best way to carry it out if you are convinced this is the exact result you want.<br>
<br>
I am speaking of course of this precise algorithm. There may be other more efficient ways of computing if you are satisfied with approximate but different results in X. We have no way of determining this without knowing a lot more about your particular goal in this updating action.<br>
<br>
Roger Stafford