0
votes

I am new to matlab. I have the task to find a principal submatrix of a given matrix where the indices to choose the principal submatrix come from a given vector. For example, suppose the matrix A is [1,2,3; 4,5,6; 7,8,9], and the vector is [1,2]. Then, the matrix we get is [1,2; 4,5]. Is there a good way to solve this? Any comments are greatly appreciated.

1

1 Answers

1
votes

That's very simple:

A = [1,2,3; 4,5,6; 7,8,9];
v = [1,2];
result = A(v,v);

I suggest you read up on matrix indexing in Matlab.