Thread Subject: Simple Question about extracting certain values from a matrix

Subject: Simple Question about extracting certain values from a matrix

From: Lazyrussian

Date: 30 Nov, 2007 17:46:16

Message: 1 of 4

Hi,

I have a 3D Matrix. I am trying to find the center of mass (using
binary values), but before I do so I need to get rid of a discrepancy
- well maybe not a discrepancy, but I want to do the following:

Remove duplicate values in each dimension.

For instance, say I have a bunch of ones scattered around this matrix,
but in a few instances their are a lot of 1s located in the 200th
column but on different rows.

How do I tell matlab to search my matrix for any values that appear
more than once, and remove all them.

I.e.

[i,j] = Find (ITV>0); %finds all coordinates that have a value of 1.
Then if I want to see what's in 'i' it displays all x-coordinates that
have a value of 1, but some of these coordinates are exactly the same.
How do I tell matlab to only display each coordinate once (so if 200
appears more than once, I want it to get rid of all the copies after
the first).

Subject: Simple Question about extracting certain values from a matrix

From: Chris

Date: 30 Nov, 2007 17:58:36

Message: 2 of 4

Lazyrussian <lazyrussian@gmail.com> wrote in message
<c4f8d1aa-f0ed-449b-a849-768c8e024ca8@e23g2000prf.googlegroups.com>...
> Hi,
>
> I have a 3D Matrix. I am trying to find the center of mass
(using
> binary values), but before I do so I need to get rid of a
discrepancy
> - well maybe not a discrepancy, but I want to do the
following:
>
> Remove duplicate values in each dimension.
>
> For instance, say I have a bunch of ones scattered around
this matrix,
> but in a few instances their are a lot of 1s located in
the 200th
> column but on different rows.
>
> How do I tell matlab to search my matrix for any values
that appear
> more than once, and remove all them.
>
> I.e.
>
> [i,j] = Find (ITV>0); %finds all coordinates that have a
value of 1.
> Then if I want to see what's in 'i' it displays all
x-coordinates that
> have a value of 1, but some of these coordinates are
exactly the same.
> How do I tell matlab to only display each coordinate once
(so if 200
> appears more than once, I want it to get rid of all the
copies after
> the first).

You can probably wrestle some profit out of 'unique'.

-Chris

Subject: Simple Question about extracting certain values from a matrix

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

Date: 30 Nov, 2007 18:04:09

Message: 3 of 4

In article <c4f8d1aa-f0ed-449b-a849-768c8e024ca8@e23g2000prf.googlegroups.com>,
Lazyrussian <lazyrussian@gmail.com> wrote:

>I have a 3D Matrix. I am trying to find the center of mass (using
>binary values), but before I do so I need to get rid of a discrepancy
>- well maybe not a discrepancy, but I want to do the following:

>Remove duplicate values in each dimension.

>For instance, say I have a bunch of ones scattered around this matrix,
>but in a few instances their are a lot of 1s located in the 200th
>column but on different rows.

>How do I tell matlab to search my matrix for any values that appear
>more than once, and remove all them.


I suggest using any()

find(any(ITV>0))
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: Simple Question about extracting certain values from a matrix

From: Lazyrussian

Date: 30 Nov, 2007 18:43:26

Message: 4 of 4

On Nov 30, 1:04 pm, rober...@ibd.nrc-cnrc.gc.ca (Walter Roberson)
wrote:
> In article <c4f8d1aa-f0ed-449b-a849-768c8e024...@e23g2000prf.googlegroups.com>,
>
> Lazyrussian <lazyruss...@gmail.com> wrote:
> >I have a 3D Matrix. I am trying to find the center of mass (using
> >binary values), but before I do so I need to get rid of a discrepancy
> >- well maybe not a discrepancy, but I want to do the following:
> >Remove duplicate values in each dimension.
> >For instance, say I have a bunch of ones scattered around this matrix,
> >but in a few instances their are a lot of 1s located in the 200th
> >column but on different rows.
> >How do I tell matlab to search my matrix for any values that appear
> >more than once, and remove all them.
>
> I suggest using any()
>
> find(any(ITV>0))
> --
> "Any sufficiently advanced bug is indistinguishable from a feature."
> -- Rich Kulawiec

Thanks to the both of you. I will try the any function momentarily.

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com