SQL like question.
Levente Torok
toroklev at gmail.com
Fri Sep 5 12:55:45 CDT 2008
Hi All,
Last time Jaroslav helped me a lot with a little trick but this time I am a little bit jammed.
I would like to get solved a simple thing again and I cannot find a fast solution to it.
I have a matrix as
m = [
1 2;
1 1;
2 3;
2 4 ];
I would like to make a unique of its first column but I would like to have the minimum of second column nearby.
So it would look like:
[ 1 1;
2 3 ]
This is something like SELECT first_col, min(second_col) FROM m GROUP BY first_col;
If I can be sure that the second nargout of unique() always points always to the last index of the same
selector item then the solution would be something like:
m = sort( m, 'descend' );
[u,i,j] = unique( m(:,1) );
m(i,:)
but
1) can I be sure about it?
2) what if I would want to make aggregate functions such as avg() or var()
Thanks a lot,
Levente
--
Blogger of http://fapuma.blogspot.com
More information about the Octave-maintainers
mailing list