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:
Help needed with indexing to the first occurrence of a value

Subject: Help needed with indexing to the first occurrence of a value

From: Jack

Date: 4 Jun, 2009 01:54:01

Message: 1 of 5

I have a single column vector "F". How can I index to the first occurrence of a the value "98". Only the row at which "98" first occurs is needed (... yes, I am a newbie to matlab). I am having trouble correctly using the find and index functions... Any help would be greatly appreciated. Thanks

Subject: Help needed with indexing to the first occurrence of a value

From: Sadik

Date: 4 Jun, 2009 02:23:01

Message: 2 of 5

You could say

firstIndex = find(F==98,1);

"Jack " <use.text.after.underscore.only_jcannon@csu.edu.au> wrote in message <h079fp$166$1@fred.mathworks.com>...
> I have a single column vector "F". How can I index to the first occurrence of a the value "98". Only the row at which "98" first occurs is needed (... yes, I am a newbie to matlab). I am having trouble correctly using the find and index functions... Any help would be greatly appreciated. Thanks

Subject: Help needed with indexing to the first occurrence of a value

From: Jack

Date: 4 Jun, 2009 02:37:35

Message: 3 of 5

Hi Sadik,

Thanks for the reply... i tried your suggestion, however the returned variable is an empty matrix...?

Jack


"Sadik " <sadik.hava@gmail.com> wrote in message <h07b65$jv8$1@fred.mathworks.com>...
> You could say
>
> firstIndex = find(F==98,1);
>
> "Jack " <use.text.after.underscore.only_jcannon@csu.edu.au> wrote in message <h079fp$166$1@fred.mathworks.com>...
> > I have a single column vector "F". How can I index to the first occurrence of a the value "98". Only the row at which "98" first occurs is needed (... yes, I am a newbie to matlab). I am having trouble correctly using the find and index functions... Any help would be greatly appreciated. Thanks

Subject: Help needed with indexing to the first occurrence of a value

From: ImageAnalyst

Date: 4 Jun, 2009 02:58:51

Message: 4 of 5

On Jun 3, 10:37 pm, "Jack "
<use.text.after.underscore.only_jcan...@csu.edu.au> wrote:
> Hi Sadik,
>
> Thanks for the reply... i tried your suggestion, however the returned variable is an empty matrix...?
>
> Jack
>
>
>
> "Sadik " <sadik.h...@gmail.com> wrote in message <h07b65$jv...@fred.mathworks.com>...
> > You could say
>
> > firstIndex = find(F==98,1);
>
> > "Jack " <use.text.after.underscore.only_jcan...@csu.edu.au> wrote in message <h079fp$16...@fred.mathworks.com>...
> > > I have a single column vector "F". How can I index to the first occurrence of a the value "98". Only the row at which "98" first occurs is needed (... yes, I am a newbie to matlab). I am having trouble correctly using the find and index functions... Any help would be greatly appreciated. Thanks- Hide quoted text -
>
> - Show quoted text -

------------------------------------------------------------------------------
Then 98 isn't in your array. Try this:
clc;
close all;
F = randperm(150)
firstIndex = find(F==98,1)

Subject: Help needed with indexing to the first occurrence of a value

From: Matt Fig

Date: 4 Jun, 2009 03:08:02

Message: 5 of 5

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <8da3ca2b-
> Then 98 isn't in your array.

At least to fp precision!


A = 98
B = 98 + eps(98)
A==B

Maybe a tolerance for comparison is needed?

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