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:
Finding like values in two dissimilar arrays...

Subject: Finding like values in two dissimilar arrays...

From: Jesse markeveys

Date: 8 Feb, 2009 19:08:02

Message: 1 of 3

example
m=[ 28,14,9,7,5.6,4.667,4,3.5,3.1]
n=[14,7,4.667,3.5,2.8,2.333,2.0,1.75,1.55]
both of these array's are of the same size.
so...
how can I configure a while/for loop to check m in descending order to find the largest common value of n=m.
  

Subject: Finding like values in two dissimilar arrays...

From: Roger Stafford

Date: 8 Feb, 2009 19:31:02

Message: 2 of 3

"Jesse markeveys" <jtm5181@psu.edu> wrote in message <gmnaii$ru8$1@fred.mathworks.com>...
> example
> m=[ 28,14,9,7,5.6,4.667,4,3.5,3.1]
> n=[14,7,4.667,3.5,2.8,2.333,2.0,1.75,1.55]
> both of these array's are of the same size.
> so...
> how can I configure a while/for loop to check m in descending order to find the largest common value of n=m.

  Presumably you are not requiring the positions in m and n to be the same in comparing their elements. (If not, it puzzles me why you require them to be the same size.)

  If not, just do an 'intersect' and select the last one in the result. You don't need to use loops on this problem.

Roger Stafford

Subject: Finding like values in two dissimilar arrays...

From: NZTideMan

Date: 8 Feb, 2009 19:34:50

Message: 3 of 3

On Feb 9, 8:08=A0am, "Jesse markeveys" <jtm5...@psu.edu> wrote:
> example
> m=3D[ 28,14,9,7,5.6,4.667,4,3.5,3.1]
> n=3D[14,7,4.667,3.5,2.8,2.333,2.0,1.75,1.55]
> both of these array's are of the same size.
> so...
> how can I configure a while/for loop to check m in descending order to fi=
nd the largest common value of n=3Dm.

Not sure why it must be a while/for loop, but to do it without a loop:
help intersect

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