Extracting data in a range

조회 수: 2 (최근 30일)
Asif Rashid
Asif Rashid 2021년 6월 28일
댓글: Star Strider 2021년 6월 28일
Hello all,
Suppose I have the following matrix 'A':
[0.1, 2, 83, 1000;
0.4, 3, 79, 1001;
0.2, 4, 91, 1018;
0.3, 5, 75, 1095]
And I want to extract a matrix B, from matrix A where the value of element of third coulum is between 70 and 80. So Matrix B would be:
[0.4, 3, 79, 1001;
0.3, 5, 75, 1095]
Thanks!

채택된 답변

Star Strider
Star Strider 2021년 6월 28일
Try this —
format short g
A = [0.1, 2, 83, 1000;
0.4, 3, 79, 1001;
0.2, 4, 91, 1018;
0.3, 5, 75, 1095];
B = A(A(:,3)>=70 & A(:,3)<=80,:)
B = 2×4
0.4 3 79 1001 0.3 5 75 1095
It creates a logical vector to address the appropriate rows, then copies all the respective columns to ‘B’.
.
  댓글 수: 2
Asif Rashid
Asif Rashid 2021년 6월 28일
Thanks. Appreciate it.
Star Strider
Star Strider 2021년 6월 28일
As always, my pleasure!

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

추가 답변 (0개)

카테고리

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

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by