find position of a element in a matrix

1 view (last 30 days)
Hi Guys,
How do I find the last element in a increasing matrix that is less than a particular number. For example if my matrix is
A=[ 1 2 3 4 6 8 9]
And I want the last number that is less than 7. So I want to find the position of 6 and not any other number like 1,2,3,4.
Thanks, NS

Accepted Answer

Walter Roberson
Walter Roberson on 22 Nov 2011
find(A < 7,1,'last')
  3 Comments
Mohamed Aly
Mohamed Aly on 3 Jun 2019
How about a certain element in the matrix? not necessarly the last one.
Would the same method applies for a 2D matrix?
Akashkumar Chovatiya
Akashkumar Chovatiya on 17 Jul 2020
How about a certain element in the matrix?

Sign in to comment.

More Answers (1)

Honglei Chen
Honglei Chen on 22 Nov 2011
You can use find
find(A<7,1,'last')
HTH
  2 Comments
Mohamed Aly
Mohamed Aly on 3 Jun 2019
How about a certain element in the matrix? not necessarly the last one.
Would the same method applies for a 2D matrix?

Sign in to comment.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!