help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Deleting equal rows/columns in matrix


From: AlbFrigerio
Subject: Re: Deleting equal rows/columns in matrix
Date: Mon, 25 Oct 2010 02:26:57 -0700 (PDT)

OK Jaroslav, here it is the code I implemented. The matrix A was my input, as
you may find in the attached file. I tried to do the same thing with general
matrices of the same size (see the initial commented lines) but every time
unique Octave beated mine ... probably I've been lucky in my example!! By
the way, my function doesn't sort the final matrix as uniques does.

% NR = 500;
% NC = 10;
% A = round(9*rand(NR,NC));
% for i=1:NR
        % if rand<0.5
                % r = 1+(NR-1)*round(rand);
                % A(i,:)=A(r,:);
        % endif
% endfor

A=load("A.txt").A;

t=time;
A_u = unique(A,"rows");
t1=time-t

A_u2 = A;
t=time;
B=A_u2*10.^[size(A_u2,2)-1:-1:0]';
D = repmat(B,1,length(B)) - repmat(B',length(B),1);
[a,b]=find(D==0);
pos=find((a-b)!=0);
        
if ~isempty(pos)
        pos=[a,b](pos,:);
        pos = pos(find(pos(:,1)>pos(:,2)),1);
        val = pos;
        if length(pos)>1
                val = values(pos);
        endif
        pos=val;
endif
A_u2(pos,:)=[];
t2=time-t

t1<t2

http://octave.1599824.n4.nabble.com/file/n3009984/A.txt A.txt 


Jaroslav Hajek-2 wrote:
> 
> 
> Yes, I understand all that. I was just curious whether you can show me
> a case where this approach actually beats Octave's unique by a
> significant margin. I'm still interested, but please give the *exact*
> code including the time measurements, I can't guess what you actually
> did.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www-old.cae.wisc.edu/mailman/listinfo/help-octave
> 
> 

-- 
View this message in context: 
http://octave.1599824.n4.nabble.com/Deleting-equal-rows-columns-in-matrix-tp3003845p3009984.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]