Creating a submatrix from a matrix

469 vues (au cours des 30 derniers jours)
Konstantinos
Konstantinos le 4 Déc 2014
Commenté : Dyuman Joshi le 12 Nov 2023
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 commentaire
said mohamed
said mohamed le 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)?

Connectez-vous pour commenter.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 4 Déc 2014
Modifié(e) : Azzi Abdelmalek le 4 Déc 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 commentaires
Himalsha Dharmapala
Himalsha Dharmapala le 25 Jan 2021
Thanks
said mohamed
said mohamed le 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)?

Connectez-vous pour commenter.

Plus de réponses (1)

VANSHUL CHOUDHARY
VANSHUL CHOUDHARY le 20 Août 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);
  2 commentaires
Justin Paulan
Justin Paulan le 12 Nov 2023
For example if the matrix is 5x5 and i want to creat a submatrix that is 2x4 it easy to just use how you showed. But i have to creat a submatrix that is 2x4 that has the first 2 rows and columns from the same position in the 5x5 but has the last two rows and columns from the middle position of the 5x5... How do i do that? Matix A is the 5x5 and i wanna get to A4 by using your method.
Dyuman Joshi
Dyuman Joshi le 12 Nov 2023
@Justin Paulan, experiment with the methods shown in the Answers in this thread.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by