필터 지우기
필터 지우기

A is a matrix , what does this statement A([1,end],[1,end]) mean ?

조회 수: 88 (최근 30일)
Muhammed Thameem
Muhammed Thameem 2020년 6월 30일
댓글: DGM 2022년 8월 25일
The result of this command gives the 4 corners of the matrix, but can't figure out how that command works

채택된 답변

madhan ravi
madhan ravi 2020년 6월 30일
That's equivalent to:
[A(1,1), A(1,end);...
A(1,end), A(end,end)]
  댓글 수: 6
Ceethal Kottakali Piyus
Ceethal Kottakali Piyus 2022년 1월 20일
Hey did you mean its equivalent to:
[A(1,1), A(1,end);...
A(end,1), A(end,end)]
or
[A(1,1), A(1,end);...
A(1,end), A(end,end)] because the second option doesn't giving the 4 corners of the matrix
DGM
DGM 2022년 8월 25일
@Ceethal Kottakali Piyus, you are correct.
A = magic(5) % an example matrix
A = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
A([1,end],[1,end])
ans = 2×2
17 15 11 9
[A(1,1), A(1,end); A(end,1), A(end,end)]
ans = 2×2
17 15 11 9
@RAVIKIRAN YALAMARTHI's answer may also serve as demonstration.

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

추가 답변 (1개)

RAVIKIRAN YALAMARTHI
RAVIKIRAN YALAMARTHI 2020년 6월 30일
Simple example:
A = [1 2 3;4 5 6;7 8 9]
A([1,end],[1,end])
ans = 2 by 2
1 3
7 9
To call the elements in a matrix, we have to mention the row and column index values.
So, A(1,2) = 2. Since, 1st row and 2nd column element is 2.
similarly, A([1,end],[1,end]) will call the elements of,
1st row & 1st column: A(1,1)
last row & 1st column: A(end,1)
1st row & last column: A(1,end)
last row & last column: A(end,end)
  댓글 수: 3
Gianpiero
Gianpiero 2022년 8월 25일
what does it mean (1:end, 1)?
DGM
DGM 2022년 8월 25일
That set of subscripts will address the first column of a matrix.
A = magic(5) % an example matrix
A = 5×5
17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9
A(1:end,1) % this is the same
ans = 5×1
17 23 4 10 11
A(:,1) % as this
ans = 5×1
17 23 4 10 11

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

카테고리

Help CenterFile Exchange에서 Operating on Diagonal Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by