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:
Search matrix for the first closest match

Subject: Search matrix for the first closest match

From: Conrad Andrew

Date: 21 Dec, 2008 23:54:02

Message: 1 of 5

I have a matrix consisting of ephemeris data as below (the ... just means i skipped some data for brevity)

A =
  354.8800
  357.7500
  0.6500
  3.5800
  6.5600
  ...
  352.6400
  355.7600
  358.9400
  0.8900
  3.7900
  6.9000

I want to be able to find the index of the first closest match to 6 within the matrix given a specific index to start the search from. Can someone show me an easy way to search the matrix? Is there a function that does this search efficiently?
Thanks!

Subject: Search matrix for the first closest match

From: NZTideMan

Date: 22 Dec, 2008 00:18:49

Message: 2 of 5

On Dec 22, 12:54=A0pm, "Conrad Andrew" <conr...@gmx.net> wrote:
> I have a matrix consisting of ephemeris data as below (the ... just means=
 i skipped some data for brevity)
>
> A =3D
> =A0 354.8800
> =A0 357.7500
> =A0 0.6500
> =A0 3.5800
> =A0 6.5600
> =A0 ...
> =A0 352.6400
> =A0 355.7600
> =A0 358.9400
> =A0 0.8900
> =A0 3.7900
> =A0 6.9000 =A0
>
> I want to be able to find the index of the first closest match to 6 withi=
n the matrix given a specific index to start the search from. Can someone s=
how me an easy way to search the matrix? Is there a function that does this=
 search efficiently?
> Thanks!

[dmn,imn]=3Dmin(abs(A(istart:end)-6));
i6=3Dimn + istart - 1;

Subject: Search matrix for the first closest match

From: Roger Stafford

Date: 22 Dec, 2008 00:21:02

Message: 3 of 5

"Conrad Andrew" <conrad7@gmx.net> wrote in message <gimkuq$l7u$1@fred.mathworks.com>...
> .......
> I want to be able to find the index of the first closest match to 6 within the matrix given a specific index to start the search from.
> ......

  When I see two superlatives specified for a single entity, it always raises a warning flag. In your particular case the obvious question is, "what makes you think the 'the closest' will be 'the soonest'?" How do you balance between how close a match the two sets of six have as compared with how far apart in the list they occur?

Roger Stafford

Subject: Search matrix for the first closest match

From: NZTideMan

Date: 22 Dec, 2008 00:58:42

Message: 4 of 5

On Dec 22, 1:21=A0pm, "Roger Stafford"
<ellieandrogerxy...@mindspring.com.invalid> wrote:
> "Conrad Andrew" <conr...@gmx.net> wrote in message <gimkuq$l7...@fred.mat=
hworks.com>...
> > .......
> > I want to be able to find the index of the first closest match to 6 wit=
hin the matrix given a specific index to start the search from.
> > ......
>
> =A0 When I see two superlatives specified for a single entity, it always =
raises a warning flag. =A0In your particular case the obvious question is, =
"what makes you think the 'the closest' will be 'the soonest'?" =A0How do y=
ou balance between how close a match the two sets of six have as compared w=
ith how far apart in the list they occur?
>
> Roger Stafford

Yes, Roger, I thought of that too, but try this:
[dmn,imn]=3Dmin(abs([rand(10,1);6;rand(10,1);6;rand(10,1)]-6))

It always gets the first one.

Subject: Search matrix for the first closest match

From: Conrad Andrew

Date: 21 Jul, 2009 02:41:03

Message: 5 of 5

NZTideMan <mulgor@gmail.com> wrote in message <626a201d-04a2-4304-a3ef-2e89da6f7ef3@s9g2000prm.googlegroups.com>...
> On Dec 22, 1:21=A0pm, "Roger Stafford"
> <ellieandrogerxy...@mindspring.com.invalid> wrote:
> > "Conrad Andrew" <conr...@gmx.net> wrote in message <gimkuq$l7...@fred.mat=
> hworks.com>...
> > > .......
> > > I want to be able to find the index of the first closest match to 6 wit=
> hin the matrix given a specific index to start the search from.
> > > ......
> >
> > =A0 When I see two superlatives specified for a single entity, it always =
> raises a warning flag. =A0In your particular case the obvious question is, =
> "what makes you think the 'the closest' will be 'the soonest'?" =A0How do y=
> ou balance between how close a match the two sets of six have as compared w=
> ith how far apart in the list they occur?
> >
> > Roger Stafford
>
> Yes, Roger, I thought of that too, but try this:
> [dmn,imn]=3Dmin(abs([rand(10,1);6;rand(10,1);6;rand(10,1)]-6))
>
> It always gets the first one.

Thanks for your replies. NZTideMan> This is what I needed. I'm sorry it took about 6months to reply to this. I thought I had done so ages ago!

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