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:
find index of repeating values in arrays

Subject: find index of repeating values in arrays

From: muzaffar

Date: 1 Jul, 2008 09:07:03

Message: 1 of 6

HI,
i have an array as: just short example

j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]

1, 2, 1 repeating values
1. i want to find out index of these repeating values.
or
2. i want to find out index of values other than repeating
units.

kind regards.

Subject: find index of repeating values in arrays

From: Steve Amphlett

Date: 1 Jul, 2008 09:50:21

Message: 2 of 6

"muzaffar " <muzaffarbashir@yahoo.com> wrote in message
<g4cs3n$mo2$1@fred.mathworks.com>...
> HI,
> i have an array as: just short example
>
> j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]
>
> 1, 2, 1 repeating values
> 1. i want to find out index of these repeating values.
> or
> 2. i want to find out index of values other than
repeating
> units.
>
> kind regards.
>

Possibly overkill, but fpat.m in the FEX will do this (and
a lot more besides) for you.

Subject: find index of repeating values in arrays

From: Jos

Date: 1 Jul, 2008 09:56:03

Message: 3 of 6

"muzaffar " <muzaffarbashir@yahoo.com> wrote in message
<g4cs3n$mo2$1@fred.mathworks.com>...
> HI,
> i have an array as: just short example
>
> j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]
>
> 1, 2, 1 repeating values
> 1. i want to find out index of these repeating values.
> or
> 2. i want to find out index of values other than repeating
> units.
>
> kind regards.
>

Assuming you know that [1 2 1] are the repeating values, try:

ind1 = strfind(j,[1 2 1])
ind2 = find(strrep(j,a,[0 0 0]) % ignore warning

if you do not know the repeating values the problem becomes
a lot tougher, and similar to pattern recognition.

hth
Jos

Subject: find index of repeating values in arrays

From: Jos

Date: 1 Jul, 2008 09:59:04

Message: 4 of 6

"muzaffar " <muzaffarbashir@yahoo.com> wrote in message
<g4cs3n$mo2$1@fred.mathworks.com>...
> HI,
> i have an array as: just short example
>
> j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]
>
> 1, 2, 1 repeating values
> 1. i want to find out index of these repeating values.
> or
> 2. i want to find out index of values other than repeating
> units.
>
> kind regards.
>

Assuming you know that [1 2 1] are the repeating values, try:

ind1 = strfind(j,[1 2 1])
ind2 = find(strrep(j,a,[0 0 0]) % ignore warning

if you do not know the repeating values the problem becomes
a lot tougher, and similar to pattern recognition.

hth
Jos

Subject: find index of repeating values in arrays

From: Nitin Chhabra

Date: 1 Jul, 2008 10:43:04

Message: 5 of 6

"muzaffar " <muzaffarbashir@yahoo.com> wrote in message
<g4cs3n$mo2$1@fred.mathworks.com>...
> HI,
> i have an array as: just short example
>
> j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]
>
> 1, 2, 1 repeating values
> 1. i want to find out index of these repeating values.
> or
> 2. i want to find out index of values other than
repeating
> units.
>
> kind regards.
>
Hi,

Here is a small algorithm to do it :
j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2];
a=unique(j);
%a=[1,2,3,4,5,6,7] is the result
then for each ith element of a make a loop
b=find(j==a(i));
% I checked for i =1 to 7 and it work
if length of b is 1 then value is index of unique element
if length of b is >1 then value is indices of repeating
element

with regards,
Nitin

Subject: find index of repeating values in arrays

From: Loren Shure

Date: 1 Jul, 2008 15:48:12

Message: 6 of 6

In article <g4cs3n$mo2$1@fred.mathworks.com>, muzaffarbashir@yahoo.com
says...
> HI,
> i have an array as: just short example
>
> j=[1,2,1,5,4,1,2,1,7,1,2,1,4,3,1,2,1,6,2]
>
> 1, 2, 1 repeating values
> 1. i want to find out index of these repeating values.
> or
> 2. i want to find out index of values other than repeating
> units.
>
> kind regards.
>
>

Maybe the function unique will help you.

--
Loren
http://blogs.mathworks.com/loren/

Tags for 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