필터 지우기
필터 지우기

Extracting Rows of a Matrix

조회 수: 224 (최근 30일)
A M
A M 2017년 3월 27일
댓글: Star Strider 2024년 2월 13일
I have a matrix 'A' of size 8*5. How to extract the first 4 rows of this Matrix.
A = 90.6848 72.5836 54.4646 36.3276 18.1728
99.7018 79.8089 59.8924 39.9521 19.9880
110.7026 88.6271 66.5192 44.3788 22.2058
124.4195 99.6278 74.7902 49.9066 24.9766
141.9931 113.7314 85.4017 57.0036 28.5365
165.3005 132.4561 99.5049 66.4459 33.2780
197.6559 158.4928 119.1482 79.6196 39.9045
245.4805 197.0868 148.3494 99.2610 49.8139
  댓글 수: 1
SURESH KUMAR
SURESH KUMAR 2023년 4월 6일
very simple
Please follow this step
Matrix_Column= A(1:4,:);

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

채택된 답변

Star Strider
Star Strider 2017년 3월 27일
First_Four_Rows = A(1:4,:);
  댓글 수: 4
A M
A M 2017년 3월 27일
Sorry for the confusion. Like all those rows whose first value is greater than 99 and less than 140, i.e. rows 2, 3 and 4
Star Strider
Star Strider 2017년 3월 28일
No worries. I needed to understand what you want.
This works:
Extracted = A((A(:,1)>99) & (A(:,1)<140),:);

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

추가 답변 (2개)

John BG
John BG 2017년 3월 27일
With
A(1:4,:)
you still get a 2D matrix as result
If you want to pull elements and get a 1D vector then
A([1:4 1:end])
same elements, lined up, 4x5 now 1x44
if you find these lines useful would you please mark my answer as Accepted Answer?
To any other reader, if you find this answer of any help, please click on the thumbs-up vote link,
thanks in advance for time and attention
John BG
  댓글 수: 1
Jan
Jan 2017년 3월 28일
If the original matrix has the dimension [8 x 5] and A M wants to extract 4 rows, how could the result be a [1 x 44] vector? Your "1:end" means "1:numel(A)" here and is not useful.

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


Maryam
Maryam 2024년 2월 13일
how we display only 2nd and 5th row of matrix T in matrix X in matlab
  댓글 수: 1
Star Strider
Star Strider 2024년 2월 13일
X_2_5 = X([2 5],:)
.

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by