From: Thomas on
How can thsi be vectorized whe lamda has a size of nx3

[l,ind] = sort(lamda,2);
for i=1:size(lamda,1)
lamda2(i,:) = lamda(i,ind(i,:));
end

Thanks thomas
From: Oleg Komarov on
"Thomas " <steinweger(a)tu-harburg.de> wrote in message <i0kc1v$628$1(a)fred.mathworks.com>...
> How can thsi be vectorized whe lamda has a size of nx3
>
> [l,ind] = sort(lamda,2);
> for i=1:size(lamda,1)
> lamda2(i,:) = lamda(i,ind(i,:));
> end
>
> Thanks thomas

isequal(l, lambda2) % 1

Oleg
From: Thomas on
"Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i0kcin$9k0$1(a)fred.mathworks.com>...
> "Thomas " <steinweger(a)tu-harburg.de> wrote in message <i0kc1v$628$1(a)fred.mathworks.com>...
> > How can thsi be vectorized whe lamda has a size of nx3
> >
> > [l,ind] = sort(lamda,2);
> > for i=1:size(lamda,1)
> > lamda2(i,:) = lamda(i,ind(i,:));
> > end
> >
> > Thanks thomas
>
> isequal(l, lambda2) % 1
>
> Oleg

Indeed, l and lamda are equal. But this doesn't matter to my question!
If you like treat this problem:

lamda = rand(10,3)-0.5;
[l,ind] = sort(abs(lamda),2);
for i=1:size(lamda,1)
lamda2(i,:) = lamda(i,ind(i,:));
end

Thomas
From: Bruno Luong on
"Thomas " <steinweger(a)tu-harburg.de> wrote in message <i0kike$ajp$1(a)fred.mathworks.com>...

> for i=1:size(lamda,1)
> lamda2(i,:) = lamda(i,ind(i,:));
> end

The for-loop can be replaced by:

m= size(lamda,1);
lamda2 = lamda(bsxfun(@plus,(ind-1)*m,(1:m)'))

% Bruno
From: Jos (10584) on
"Thomas " <steinweger(a)tu-harburg.de> wrote in message <i0kike$ajp$1(a)fred.mathworks.com>...
> "Oleg Komarov" <oleg.komarovRemove.this(a)hotmail.it> wrote in message <i0kcin$9k0$1(a)fred.mathworks.com>...
> > "Thomas " <steinweger(a)tu-harburg.de> wrote in message <i0kc1v$628$1(a)fred.mathworks.com>...
> > > How can thsi be vectorized whe lamda has a size of nx3
> > >
> > > [l,ind] = sort(lamda,2);
> > > for i=1:size(lamda,1)
> > > lamda2(i,:) = lamda(i,ind(i,:));
> > > end
> > >
> > > Thanks thomas
> >
> > isequal(l, lambda2) % 1
> >
> > Oleg
>
> Indeed, l and lamda are equal. But this doesn't matter to my question!
> If you like treat this problem:
>
> lamda = rand(10,3)-0.5;
> [l,ind] = sort(abs(lamda),2);
> for i=1:size(lamda,1)
> lamda2(i,:) = lamda(i,ind(i,:));
> end
>
> Thomas

Oleg gave you a valid question to your original question, so you really should write

"but this doesn't matter to my OTHER question".

Anywats, you might be interested in my (vectorized) function SORTLIND, available on the FEX:
http://www.mathworks.com/matlabcentral/fileexchange/19443

lamda = rand(10,3)-0.5;
[unused, ind] = sortlind(abs(lamda),2);
lamda2 = lamda(ind)

Alternatively, you could pre-allocate lamda2 making the for-loop pretty fast as well:

lamda2 = zeros(size(lamda)) ;
for i=1:size(lamda,1)
lamda2(i,:) = lamda(i,ind(i,:));
end

hth
Jos