Got Questions? Get Answers.
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:
getting the matrix index

Subject: getting the matrix index

From: Jehad Zughyer

Date: 18 Jul, 2008 17:03:02

Message: 1 of 4

Suppose I have an [m,n] matrix. how do i get the (I,j)
index of the first cell in column j with a value > larger
than say x.

Subject: getting the matrix index

From: matt dash

Date: 18 Jul, 2008 18:14:02

Message: 2 of 4

"Jehad Zughyer" <zjehad@yahoo.com> wrote in message
<g5qic6$js5$1@fred.mathworks.com>...
> Suppose I have an [m,n] matrix. how do i get the (I,j)
> index of the first cell in column j with a value > larger
> than say x.


If your matrix is A:

i=find(A(:,j)>=x,1);

Subject: getting the matrix index

From: Jehad Zughyer

Date: 18 Jul, 2008 19:30:18

Message: 3 of 4

"matt dash" <n.a@mail.com> wrote in message
<g5qmha$eff$1@fred.mathworks.com>...
> "Jehad Zughyer" <zjehad@yahoo.com> wrote in message
> <g5qic6$js5$1@fred.mathworks.com>...
> > Suppose I have an [m,n] matrix. how do i get the (I,j)
> > index of the first cell in column j with a value >
larger
> > than say x.
>
>
> If your matrix is A:
>
> i=find(A(:,j)>=x,1);
Thanks Matt,
I was able to resolve my problem using the find function.
However, I am curious, why number 1 in the syntax you sent,
I had not used it. Actualy, I got an error statment of too
much input argument!

Subject: getting the matrix index

From: Matt Fig

Date: 18 Jul, 2008 20:49:03

Message: 4 of 4

I am curious, why number 1 in the syntax you sent,
> I had not used it. Actualy, I got an error statment of too
> much input argument!

The second argument to the find function (1 in this case)
tells Matlab to return the first value found. Older
versions of Matlab do not have this feature.

A = magic(5)
ii = find(A(:,3)>=8,1) % Returns 3


For older versions, this is equivalent to:


A = magic(5)
ii = find(A(:,3)>=8); % Returns [3;4;5]
ii = ii(1) % Returns 3

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