The problem of extracting elements from MATLAB matrix Extract some elements from a matrix to form a one-dimensional array (vector), and know the coordinates to be extracted detailed description: In the known matrix, a = [1,2,3; 4,5,6; 7,8,9]; To take out the three elements (1,1) (2,3) (3,2) and form an array [1,8,6] The element coordinates are stored in two arrays: a=[1 2 3]; b=[1 3 2]; Note: it is best not to use circulation

The problem of extracting elements from MATLAB matrix Extract some elements from a matrix to form a one-dimensional array (vector), and know the coordinates to be extracted detailed description: In the known matrix, a = [1,2,3; 4,5,6; 7,8,9]; To take out the three elements (1,1) (2,3) (3,2) and form an array [1,8,6] The element coordinates are stored in two arrays: a=[1 2 3]; b=[1 3 2]; Note: it is best not to use circulation


A=[1,2,3;4,5,6;7,8,9];
a=[1 2 3];
b=[1 3 2];
C(1)=A(a(1),b(1));
C(2)=A(a(2),b(2));
C(3)=A(a(3),b(3));
It's very simple to use the loop,
A=[1,2,3;4,5,6;7,8,9];
a=[1 2 3];
b=[1 3 2];
for i=1:3
C(i)=A(a(i),b(i))
end
By the way, according to your order (1,1) (2,3) (3,2), the array should be [1,6,8]
If it is [1 8 6]
Use the following code:
A=[1,2,3;4,5,6;7,8,9];
a=[1 2 3];
b=[1 3 2];
C(1)=A(a(1),b(1));
C(2)=A(a(3),b(3));
C(3)=A(a(2),b(2));



In MATLAB, a part of the known matrix is extracted to form a new matrix
Specifically, for example, if there is a matrix of n * n, I want to form a new matrix by removing columns K to m from rows I to J. how can I achieve this?


A=reshape(1:56,7,8)
A (2:3,:) = []% remove lines 2 to 3
A (:, 1:5) =]% remove columns 1 to 5



In MATLAB, how to extract a matrix of a row of elements or extract a column of elements?
For example, extract the first row elements from a 6 * 6 matrix to form a 6-dimensional row vector


Methods: a (I,:) extracts the i-th row of matrix A. A (:, I) extracts the i-th column of matrix A to give you an example: > > A = [1:6; 2:7; 3:8; 4:9; 5:10; 6:11] a (1,:) a (:, 1) a = 1 23 4 5 62 3 4 5 6 73 4 5 6 7 84 5 6 7 8 95 6 7 8 9 9 106 7 9 10 11 ans = 1 23 4