Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
avoid for

Subject: avoid for

From: Blue gRay

Date: 16 Jul, 2010 18:04:51

Message: 1 of 3

Hi,

I have a matrix X [m x n] and a vector Y [m x 1]

I want to update X following this algorithm

   for i=1:m
       for j=1:m
           if Y(j)<Y(i)
               rj = sqrt(sum((X(i,:)-X(j,:)).^2));
               B = rj*coeff;
               X(i,:) = (1-B)*X(i,:) + B*X(j,:) + ui(iter,:);
           end
       end
   end

A professor said me that there is a possibility to avoid the 2 cycles and
make it just by matrix operations (not exactly that algorithm but similar,
by considering the coefficient B in the (1-B)*X(i,:) like the mean of all
the B for the j that satify Y(j)<Y(i) )

I am trying to figure out how to do that but without success.
Do someone see some tricky solution for it?

Cheers

fff
 



--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Subject: avoid for

From: Travis Knepp

Date: 16 Jul, 2010 20:47:05

Message: 2 of 3

"Blue gRay" <ffffffffffffffff@hotmail.com> wrote in message <i1q705$2egd$1@adenine.netfront.net>...
> Hi,
>
> I have a matrix X [m x n] and a vector Y [m x 1]
>
> I want to update X following this algorithm
>
> for i=1:m
> for j=1:m
> if Y(j)<Y(i)
> rj = sqrt(sum((X(i,:)-X(j,:)).^2));
> B = rj*coeff;
> X(i,:) = (1-B)*X(i,:) + B*X(j,:) + ui(iter,:);
> end
> end
> end
>
> A professor said me that there is a possibility to avoid the 2 cycles and
> make it just by matrix operations (not exactly that algorithm but similar,
> by considering the coefficient B in the (1-B)*X(i,:) like the mean of all
> the B for the j that satify Y(j)<Y(i) )
>
> I am trying to figure out how to do that but without success.
> Do someone see some tricky solution for it?
>
> Cheers
>
> fff
>
>
>
>
> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---


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.

Subject: avoid for

From: Roger Stafford

Date: 16 Jul, 2010 21:19:04

Message: 3 of 3

"Blue gRay" <ffffffffffffffff@hotmail.com> wrote in message <i1q705$2egd$1@adenine.netfront.net>...
> Hi,
>
> I have a matrix X [m x n] and a vector Y [m x 1]
>
> I want to update X following this algorithm
>
> for i=1:m
> for j=1:m
> if Y(j)<Y(i)
> rj = sqrt(sum((X(i,:)-X(j,:)).^2));
> B = rj*coeff;
> X(i,:) = (1-B)*X(i,:) + B*X(j,:) + ui(iter,:);
> end
> end
> end
>
> A professor said me that there is a possibility to avoid the 2 cycles and
> make it just by matrix operations (not exactly that algorithm but similar,
> by considering the coefficient B in the (1-B)*X(i,:) like the mean of all
> the B for the j that satify Y(j)<Y(i) )
>
> I am trying to figure out how to do that but without success.
> Do someone see some tricky solution for it?
>
> Cheers
> fff
- - - - - - - - -
  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.

  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.

  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.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us