From: "Jan Simon" <>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Getting indexes of rows of matrix with more than n repetitions
Date: Wed, 6 Jan 2010 19:50:19 +0000 (UTC)
Organization: Universit&#228;t Heidelberg
Lines: 25
Message-ID: <hi2phr$5nj$>
References: <hhudae$4p$> <hhuths$led$> <hi023t$mtq$> <hi1f7i$plv$> <hi1g5n$f7i$> <hi1ua1$d7e$> <hi2300$6dk$> <hi24al$3ig$> <hi290i$dsp$> <hi2fj5$pr2$> <hi2gdc$j3u$> <hi2im0$fbd$>
Reply-To: "Jan Simon" <>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1262807419 5875 (6 Jan 2010 19:50:19 GMT)
NNTP-Posting-Date: Wed, 6 Jan 2010 19:50:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869888
Xref: comp.soft-sys.matlab:596971

Dear Matt!

> >      [foo,foo,foo,goo,goo]=f();
> I know you use this approach, as I do.  I was asking why other folks prefer to create a dummy variable in the workspace.  

The dummy is created with this also, but immediately overwritten!

If I have a giantic vector, which nearly fills my memory, and I want to sort it with:
  [dummy, index] = sort(Array);
  [index, index] = sort(Array);
in both cases the array is created (any different opinions?)!
In the case of cell strings, the sorted array contains shared data copied - fortuantely. But if I never need the sorted array, it would be nice to have a SORTIND, which replies just the index vector. Is anybody willing to publish a MEX wrapper for a quicksort???

That [index] and [index] have the same address is not really surprising. It is the same variable. You do not need a FORMAT DEBUG for that.

I failed: Matlab 6.5 has not a sort.c, but sortcellchar.c. This exists in Matlab 7.8 also, but is not documented. Lukily this solves my question for cell strings.
The MEX function sortrowsc.c is not an alternative, because it is 6 times slower than SORT if applied to a single column (why?!).

If I show "[index, index] = sort(Array)" to a Matlab beginner, I have to explain, that I assume, that the output arguments of a function are assigned from the left to the right.
If I show "[dummy, index] = sort(Array)", I do not have to explain anything.

Kind regards, Jan

BTW. Has the OP tested my try to solve the problem faster than UNIQUE/HISTC/ISMEMBC ?