Return the number of rows of an array

10 views (last 30 days)
Riley
Riley on 25 May 2021
Commented: Riley on 25 May 2021
Hi, I just started using Matlab and is confused on how to extract the row indices/ row numbers.
For example, I have a function A:
A = [10 20 30 40 50 60 70 80 90 100]
I wanted to extract the row which has elements less than 50 so it will give
B= [1 2 3 4] (from row 1 to 4)
May I know how to do this? Any help and advice is greatly appreciated
  1 Comment
Stephen23
Stephen23 on 25 May 2021
You seem to have confused rows with columns:
Your example A has only one row and ten columns, whereas your example B has one row and five columns.

Sign in to comment.

Accepted Answer

Stephan
Stephan on 25 May 2021
A = [10 20 30 40 50 60 70 80 90 100]
A = 1×10
10 20 30 40 50 60 70 80 90 100
B = A(A<50)
B = 1×4
10 20 30 40
  3 Comments
Stephan
Stephan on 25 May 2021
A = [10 20 30 40 50 60 70 80 90 100]
A = 1×10
10 20 30 40 50 60 70 80 90 100
[row, col] = find(A<50)
row = 1×4
1 1 1 1
col = 1×4
1 2 3 4

Sign in to comment.

More Answers (1)

Alex Alex
Alex Alex on 25 May 2021
B=find(A<50)
  2 Comments
Stephen23
Stephen23 on 25 May 2021
Note that strictly this returns the linear indices, not row (or column) subscript indices.

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!