Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

matrix manipulation : ind of wanted rows and columns stocked in a vector

조회 수: 1 (최근 30일)
Lila wagou
Lila wagou 2017년 4월 7일
마감: MATLAB Answer Bot 2021년 8월 20일
Dear all, for a square matrix is it possible to get only the the first and the third (not the second) rows and columns : the wanted are stocked in a B vector
A =
35 6 19
3 7 23
31 2 27
B = (1 3)
C = function (A, B)
C =
35 19
31 27

답변 (1개)

David Goodmanson
David Goodmanson 2017년 4월 7일
편집: David Goodmanson 2017년 4월 7일
Hi Lila, you just have to make an index vector:
B = [1 3];
C = A(B,B)
The row index is the first listed and the column index is second, and these can be independent:
>> A = magic(5)
A = 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
>> C = A([1 3 4],[3 5])
C = 1 15
13 22
19 3

이 질문은 마감되었습니다.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by