What is the meaning of sol(31,: ,1)

조회 수: 12 (최근 30일)
Maria Jessica Borja Portugal
Maria Jessica Borja Portugal 2022년 1월 16일
편집: John D'Errico 2022년 1월 16일
What is the meaning of A(31,: ,1)? If A is a matrix. Thanks

채택된 답변

John D'Errico
John D'Errico 2022년 1월 16일
편집: John D'Errico 2022년 1월 16일
Do you understand indexing? Perhaps you really need to start with a tutorial, the Onramp tutorials may be a good place to start.
If A is a matrix,
A = magic(5)
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
then you can index into the matrix. A colon as an index tells MATLAB to take all of the elements in that row or column, etc.
A(3,:)
ans = 1×5
4 6 13 20 22
So A(3,:) extracts the 3rd row, with all of the elements in that row.
But all matrices in MATLAB can also be viewed as higher dimensional matrices. So a 5x5 matrix, is also a 5x5x1 matrix. So this:
A(3,:,1)
ans = 1×5
4 6 13 20 22
does exactly the same thing. Or, we might have a matrix with multiple true planes in that matrix.
A = randi(5,[3,4,2])
A =
A(:,:,1) = 3 2 4 2 5 2 5 5 3 3 3 5 A(:,:,2) = 2 5 1 5 4 3 2 2 5 4 4 1
So that matrix now has 2 planes, EACH of which is a 3x4 matrix. Now
A(:,3,2)
ans = 3×1
1 2 4
That extracted the third column, of the 2nd plane of the matrix. The result is 3x1 vector.

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by