Prev: Adapt function problem
Next: Help on implementing motor torque control reg with already available inefficient motor
From: Thomas on 2 Jul 2010 08:35 "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <i0kl4h$n0r$1(a)fred.mathworks.com>... > "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 'sortlind' works fine! Thans a lot, Thomas
From: Thomas on 2 Jul 2010 08:38 "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <i0kl4h$n0r$1(a)fred.mathworks.com>... > "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 'sortlind' works fine - Thanks for this nice programming! Thomas
From: Oleg Komarov on 2 Jul 2010 09:21 "Jos (10584) " > > Oleg gave you a valid question to your original question, so you really should write > > "but this doesn't matter to my OTHER question". > Thanks Jos. It was not my intention to make a fuss about the question but the level of requests on this forum vary a lot, consequently I never discard the most trivial solution (which was not per se excluded by the question itself). Oleg
From: Matt J on 2 Jul 2010 09:49 "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 ==================== If lamda is only nx3, I would actually expect a for-loop over columns, as opposed to rows, to be the most efficient approach, faster even than anything vectorized: for i=1:size(lamda,2) lamda2(:,i) = lamda(ind(:,i),i); end
From: Bruno Luong on 2 Jul 2010 10:06 > > If lamda is only nx3, I would actually expect a for-loop over columns, as opposed to rows, to be the most efficient approach, faster even than anything vectorized: > > for i=1:size(lamda,2) > > lamda2(:,i) = lamda(ind(:,i),i); > > end Nice try, but I believe that's won't work. Bruno
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 Prev: Adapt function problem Next: Help on implementing motor torque control reg with already available inefficient motor |