Creating a submatrix from a matrix
135 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Konstantinos
am 4 Dez. 2014
Kommentiert: Gabriele Bunkheila
am 3 Dez. 2024
I want a code to create a matrix which consist of rows and columns of another matrix.
i.e. A (4X4) = [ 1 2 3 4; 5 6 7 8; 1 3 5 7; 2 4 6 8; ]
The submatrix B consist of the { 1, 2, 4 }rows of A and the { 2,3 }columns of A:
Β (3Χ2) = [ 2 3; 6 7; 4 6; ]
Any help could be useful.
Thanks in advance!
1 Kommentar
said mohamed
am 5 Mai 2021
Using the matrix A = [5 1 11; 7 13 3; 8 5 2], the matrix B is constructed as B = [A A A; A A A; A A A]. Which of the following is the result of the operation K = L * J, made using the submatrices of matrix B, L = B (1: 3,3: 5) and J = B (2: 4,2: 3)?
Akzeptierte Antwort
Azzi Abdelmalek
am 4 Dez. 2014
Bearbeitet: Azzi Abdelmalek
am 4 Dez. 2014
A= [ 1 2 3 4; 5 6 7 8; 1 3 5 7; 2 4 6 8; ]
B=A([1 2 4],[2 3])
6 Kommentare
said mohamed
am 5 Mai 2021
Using the matrix A = [5 1 11; 7 13 3; 8 5 2], the matrix B is constructed as B = [A A A; A A A; A A A]. Which of the following is the result of the operation K = L * J, made using the submatrices of matrix B, L = B (1: 3,3: 5) and J = B (2: 4,2: 3)?
Weitere Antworten (1)
VANSHUL CHOUDHARY
am 20 Aug. 2021
A = rand(4,3);
% Get those elements of A that are located in rows 3 to 4 and
% column 2 to 3.
sub_matrix = A(3:4,2:3);
4 Kommentare
Gabriele Bunkheila
am 3 Dez. 2024
Please note:
- With matrices, the first dimesion is always the number of row, the second is the number of columns. So in this case A is 5x5 (size(A) would return [5,5]) and A4 is 4x2 (size(A4) would return [4,2]).
- A4 here seems composed of two "stacked" (or vertically concatenated) 2x2 sub-matrices of A
A possible way to obtain A4 from A is the following;
A = [1:5; 0.5*(-10:-6); 0.1*0:4; 10:-1:6; 2*(1:5)]
rows1 = [1, 2];
cols1 = [1, 2];
rows2 = [3, 4];
cols2 = [3, 4];
A4 = [A(rows1, cols1); A(rows2, cols2)]
@Ioannis Aggelos I hope this helps.
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

