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 same value

Subject: find same value

From: pink

Date: 9 Jun, 2011 00:02:02

Message: 1 of 9

how do I find the same value in the matrix a(:,1)
a=[1 34;
     2 33;
     2 45;
     3 32;
     4 65;
     4 99;
     5 11;
     1 33;
     6 22]
if %same value
 warndlg ('xxxxx')
else
end

Subject: find same value

From: Roger Stafford

Date: 9 Jun, 2011 01:14:05

Message: 2 of 9

"pink" wrote in message <isp2hq$ot$1@newscl01ah.mathworks.com>...
> how do I find the same value in the matrix a(:,1)
- - - - - - - -
  When you say "same", do you mean contiguous elements that are equal or do you mean any two elements that are equal? If by "find" you mean you want to locate the repeating elements, which of their indices do you want?

  This will give the index of the second of any equal contiguous pair:

 f = find(diff(A(:,1))==0)+1;

Roger Stafford

Subject: find same value

From: ImageAnalyst

Date: 9 Jun, 2011 01:15:59

Message: 3 of 9

How about using hist(), something like
counts = hist(a(:,1))
If counts >=2 there are repeats, which you can find with find().

Subject: find same value

From: pink

Date: 9 Jun, 2011 16:19:04

Message: 4 of 9

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <3bc3d24c-d131-41bd-a180-32f439c2f03f@l18g2000yql.googlegroups.com>...
> How about using hist(), something like
> counts = hist(a(:,1))
> If counts >=2 there are repeats, which you can find with find().

I just wanted to check the data (matrix) if the (:, 1) there is or is not the same value, if it will it will display the message "warndlg"

Subject: find same value

From: Roger Stafford

Date: 9 Jun, 2011 16:50:21

Message: 5 of 9

"pink" wrote in message <isqrpo$r95$1@newscl01ah.mathworks.com>...
> I just wanted to check the data (matrix) if the (:, 1) there is or is not the same value, if it will it will display the message "warndlg"
- - - - - - - -
  You didn't answer the question I asked about what you meant by "same". Here are tests for either meaning:

1. If "same" refers only to contiguous elements:

 t = any(diff(A(:,1)==0));

2. If "same" refers to any pair of elements within the vector:

 t = any(diff(sort(A(:,1))==0));

Roger Stafford

Subject: find same value

From: pink

Date: 9 Jun, 2011 18:25:05

Message: 6 of 9

"Roger Stafford" wrote in message <isqtkd$3em$1@newscl01ah.mathworks.com>...
> "pink" wrote in message <isqrpo$r95$1@newscl01ah.mathworks.com>...
> > I just wanted to check the data (matrix) if the (:, 1) there is or is not the same value, if it will it will display the message "warndlg"
> - - - - - - - -
> You didn't answer the question I asked about what you meant by "same". Here are tests for either meaning:
>
> 1. If "same" refers only to contiguous elements:
>
> t = any(diff(A(:,1)==0));
>
> 2. If "same" refers to any pair of elements within the vector:
>
> t = any(diff(sort(A(:,1))==0));
>
> Roger Stafford
soory roger, not work
I just wanted to check first column element
A=[1 34;
     2 33;
     2 45;
     3 32;
     4 65;
     4 99;
     5 11;
     1 33;
     6 22]
on A (:, 1) there are 3 number the same, then A = 1
A=[1 34;
     2 33;
     3 45;
     4 32;
     5 65;
     6 99;
     7 11;
     8 33;
     9 22]
on A (:, 1) there is not the same numbers, then A = 0

Subject: find same value

From: Roger Stafford

Date: 9 Jun, 2011 18:56:04

Message: 7 of 9

"pink" wrote in message <isr361$k4s$1@newscl01ah.mathworks.com>...
> "Roger Stafford" wrote in message <isqtkd$3em$1@newscl01ah.mathworks.com>...
> > "pink" wrote in message <isqrpo$r95$1@newscl01ah.mathworks.com>...
> > > I just wanted to check the data (matrix) if the (:, 1) there is or is not the same value, if it will it will display the message "warndlg"
> > - - - - - - - -
> > You didn't answer the question I asked about what you meant by "same". Here are tests for either meaning:
> >
> > 1. If "same" refers only to contiguous elements:
> >
> > t = any(diff(A(:,1)==0));
> >
> > 2. If "same" refers to any pair of elements within the vector:
> >
> > t = any(diff(sort(A(:,1))==0));
> >
> > Roger Stafford
> soory roger, not work
> I just wanted to check first column element
> A=[1 34;
> 2 33;
> 2 45;
> 3 32;
> 4 65;
> 4 99;
> 5 11;
> 1 33;
> 6 22]
> on A (:, 1) there are 3 number the same, then A = 1
> A=[1 34;
> 2 33;
> 3 45;
> 4 32;
> 5 65;
> 6 99;
> 7 11;
> 8 33;
> 9 22]
> on A (:, 1) there is not the same numbers, then A = 0
- - - - - - - -
  I cannot help you any further if you continue to avoid answering my question. It's a reasonable question to ask.

Roger Stafford

Subject: find same value

From: Roger Stafford

Date: 9 Jun, 2011 19:29:06

Message: 8 of 9

  My apologies. You apparently did give an indirect answer in implying the two 1's were the "same".

  Also I apologize for my two solutions which have misplaced parentheses. The second solution should be:

 t = any(diff(sort(A(:,1)))==0);

(and a similar correction for the first one.)

Roger Stafford

Subject: find same value

From: pink

Date: 9 Jun, 2011 19:30:21

Message: 9 of 9

"Roger Stafford" wrote in message <isr504$ps7$1@newscl01ah.mathworks.com>...
> "pink" wrote in message <isr361$k4s$1@newscl01ah.mathworks.com>...
> > "Roger Stafford" wrote in message <isqtkd$3em$1@newscl01ah.mathworks.com>...
> > > "pink" wrote in message <isqrpo$r95$1@newscl01ah.mathworks.com>...
> > > > I just wanted to check the data (matrix) if the (:, 1) there is or is not the same value, if it will it will display the message "warndlg"
> > > - - - - - - - -
> > > You didn't answer the question I asked about what you meant by "same". Here are tests for either meaning:
> > >
> > > 1. If "same" refers only to contiguous elements:
> > >
> > > t = any(diff(A(:,1)==0));
> > >
> > > 2. If "same" refers to any pair of elements within the vector:
> > >
> > > t = any(diff(sort(A(:,1))==0));
> > >
> > > Roger Stafford
> > soory roger, not work


> > I just wanted to check first column element
> > A=[1 34;
> > 2 33;
> > 2 45;
> > 3 32;
> > 4 65;
> > 4 99;
> > 5 11;
> > 1 33;
> > 6 22]
> > on A (:, 1) there are 3 number the same, then A = 1
> > A=[1 34;
> > 2 33;
> > 3 45;
> > 4 32;
> > 5 65;
> > 6 99;
> > 7 11;
> > 8 33;
> > 9 22]
> > on A (:, 1) there is not the same numbers, then A = 0
> - - - - - - - -
> I cannot help you any further if you continue to avoid answering my question. It's a reasonable question to ask.
>
> Roger Stafford

I just wanted to check, whether the data (:, 1) there is the same value.

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