Return the number of rows of an array

조회 수: 4 (최근 30일)
Riley
Riley 2021년 5월 25일
댓글: Riley 2021년 5월 25일
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
Stephen23
Stephen23 2021년 5월 25일
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.

댓글을 달려면 로그인하십시오.

채택된 답변

Stephan
Stephan 2021년 5월 25일
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
Stephan
Stephan 2021년 5월 25일
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
Riley
Riley 2021년 5월 25일
Thanks, Stephen!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Alex Alex
Alex Alex 2021년 5월 25일
B=find(A<50)
  댓글 수: 2
Stephen23
Stephen23 2021년 5월 25일
Note that strictly this returns the linear indices, not row (or column) subscript indices.
Riley
Riley 2021년 5월 25일
Thanks, Alex

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by