Thread Subject: removing identical matrix elements

Subject: removing identical matrix elements

From: Omni Domni

Date: 6 Mar, 2008 01:37:02

Message: 1 of 3

Hello,

Suppose we have a matrix of the form
A=[1 5 4 1 6 6 1]
What is the fastest way to create a new matrix that
contains each element of A only once:
B=[1 5 4 6]
note: matrix A contains only integers

Subject: removing identical matrix elements

From: us

Date: 6 Mar, 2008 01:49:03

Message: 2 of 3

"Omni Domni":
<SNIP unique member evergreen

one of the many solutions

     a=[1 5 4 1 6 6 1]
     [ix,ix]=unique(a,'first');
     r=a(sort(ix))
%{
     a=
          1 5 4 1 6 6 1
     r=
          1 5 4 6
%}

us

Subject: removing identical matrix elements

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 Mar, 2008 04:38:56

Message: 3 of 3

In article <fqnhru$je3$1@fred.mathworks.com>,
Omni Domni <eloykarakh@hotmail.com> wrote:

>Suppose we have a matrix of the form
>A=[1 5 4 1 6 6 1]
>What is the fastest way to create a new matrix that
>contains each element of A only once:
>B=[1 5 4 6]
>note: matrix A contains only integers

Asking for the "fastest way" is always a bit troublesome.
The "fastest way" may depend upon the number of inputs, or upon
the amount of repetition, or upon the range of values involved
and the amount of memory available. And on some platforms,
the "fastest" way might involve writing a MEX routine that exploits
processor-specific instructions. For example, if all of the
integer values turn out to be exactly representable in single
precision then using single precision SSE instructions might
turn out to be faster above a minimum vector size... but on
a different processor in the same family, SSE instructions might
turn out to be slower than using double precision and multiple
floating point instructions (because there might be multiple cores
and although each double precision instruction might be slower than
an SSE single precision instruction, you wouldn't have contention
from both cores trying to use the same SSE unit.)

--
  "Tired minds don't plan well. Sleep first, plan later."
                                              -- Walter Reisch

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
sort us 5 Mar, 2008 20:50:09
code us 5 Mar, 2008 20:50:09
unique us 5 Mar, 2008 20:50:09
evergreen us 5 Mar, 2008 20:50:09
matrix manipula... Omni Domni 5 Mar, 2008 20:39:56
rssFeed for this Thread

Contact us at files@mathworks.com