From: Jan Simon on 6 Jan 2010 07:05 Dear Sudheer! > > > Now It is taking 30 sec . It is great when It is compared to 1300 sec. Is there any fast way to do than taking 30 sec. > > [vu,vx,vx]=unique(v,'rows'); > > vn=histc(vx,1:max(vx)); > > ix=find(ismembc(vx,find(vn>=n))).' % <- ISMEMBC For some test data this is faster than UNIQUE/HISTC/ISMEMBC: % ---------------------------------------- 8< --------------------- function Index = test2(x, Len) [m, n] = size(x); % Inlined SORTROWS: [v, ind1] = sort(x(:, 2)); [v, ind2] = sort(x(ind1, 1)); ind = ind1(ind2); y = x(ind, :); % Logical vector, TRUE for new values, FALSE for repeated values: d(2:m) = any(diff(y, 1, 1), 2); d(1) = true; % Determine distance of TRUE values: Dist = diff([find(d), m + 1]); List(ind) = Dist(cumsum(d)); Index = find(List >= Len); % ------------- >8 ------------------------------------------------ Perhaps this is faster for the real data. But again: 1. If the values of the 2 columns could be combined, the sorting is much faster. 2. If the function is called multiple times for the same data, sorting it once promisses more speed than any advanced tricks inside the routine. It would be nice to have a function SORTIND with replying just the sorting index. This would save time in many of my functions. Is this implemented already? Kind regards, Jan
From: Jos (10584) on 6 Jan 2010 08:25 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message * snip * > It would be nice to have a function SORTIND with replying just the sorting index. This would save time in many of my functions. Is this implemented already? Hi Jan, Do you mean the equivalent of the following function function SortIndex = sortind(varargin) [Dummy, SortIndex] = sort(varargin{:}) Jos
From: Bruno Luong on 6 Jan 2010 08:48 "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hi2300$6dk$1(a)fred.mathworks.com>... > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message > * snip * > > It would be nice to have a function SORTIND with replying just the sorting index. This would save time in many of my functions. Is this implemented already? > > > Hi Jan, > > Do you mean the equivalent of the following function > > function SortIndex = sortind(varargin) > [Dummy, SortIndex] = sort(varargin{:}) > > Jos Of course, newer Matlab has the "titled" syntax for optional input/output arguments, and this can be applied for all functions. I tend not to use it because of the backward incompatible. Bruno
From: Jan Simon on 6 Jan 2010 09:12 Dear Jos! > Do you mean the equivalent of the following function > > function SortIndex = sortind(varargin) > [Dummy, SortIndex] = sort(varargin{:}) > > Jos Exactly. Creating [Dummy] wastes time in many of my functions. SORT was a MEX in Matlab 6.5 (with C-source code), so it should be easy to omit the output. Nevertheless I'm unsure ever, if this collides with the license conditions... Kind regards, Jan
From: Jos (10584) on 6 Jan 2010 10:08
"Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hi24al$3ig$1(a)fred.mathworks.com>... > "Jos (10584) " <#10584(a)fileexchange.com> wrote in message <hi2300$6dk$1(a)fred.mathworks.com>... > > "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message > > * snip * > > > It would be nice to have a function SORTIND with replying just the sorting index. This would save time in many of my functions. Is this implemented already? > > > > > > Hi Jan, > > > > Do you mean the equivalent of the following function > > > > function SortIndex = sortind(varargin) > > [Dummy, SortIndex] = sort(varargin{:}) > > > > Jos > > Of course, newer Matlab has the "titled" syntax for optional input/output arguments, and this can be applied for all functions. > > I tend not to use it because of the backward incompatible. > > Bruno I agree with you on this, Bruno. I'll wait till I have no more access to old versions before using the tilde. However, I doubt using the tilde is faster than using the dummy variable, since the memory for this variable is created within sort itself. I do not think that memory is actually being copied to the dummy variable. Jos |