Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
ismember index (loc) double why?

Subject: ismember index (loc) double why?

From: Mike

Date: 12 May, 2011 02:34:57

Message: 1 of 2

Hi,

set = [0 2 4 6 8 10 12 14 16 18 20];
a = (1:5)'
set = [5 2 4 2 8 10 12 2 16 18 20 3];
[tf, index] = ismember(a, set);
>> whos index
  Name Size Bytes Class Attributes

  index 5x1 40 double
>> index

index =

     0
     2
     0
     3
     0
>> set(index)
??? Subscript indices must either be real positive integers or
logicals.

I am wondering why index is not logical. When will we use when index
is double?
Mike

Subject: ismember index (loc) double why?

From: Roger Stafford

Date: 12 May, 2011 05:34:05

Message: 2 of 2

Mike <sulfateion@gmail.com> wrote in message <362d4b17-fdf2-4d5d-bf71-1f57a9a86085@s41g2000prb.googlegroups.com>...
> Hi,
>
> set = [0 2 4 6 8 10 12 14 16 18 20];
> a = (1:5)'
> set = [5 2 4 2 8 10 12 2 16 18 20 3];
> [tf, index] = ismember(a, set);
> >> whos index
> Name Size Bytes Class Attributes
>
> index 5x1 40 double
> >> index
>
> index =
>
> 0
> 2
> 0
> 3
> 0
> >> set(index)
> ??? Subscript indices must either be real positive integers or
> logicals.
>
> I am wondering why index is not logical. When will we use when index
> is double?
> Mike
- - - - - - - - -
  As you can see, some of the values of 'index' are zero corresponding to those elements of 'a' which are not in 'set'. That means you must not write "set(index)" as you have done, because Matlab will complain about the zero values for indices. You can write "set(index(tf))" to exclude the zero values in 'index'. The "index(tf)" part will be [2,3] showing where the first occurrences of 2 and 4 are located in 'set' and "set(index(tf))" would then give [2,4] which are those first 'set' values. Is that what you are seeking?

  By all means, read the documentation for 'ismember' carefully and always remember to avoid zero values for quantities that are to act as indices.

Roger Stafford

Tags for this Thread

No tags are associated with this thread.

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.

Contact us