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

said mohamed
said mohamed 2021년 5월 5일
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)?

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 12월 4일
편집: Azzi Abdelmalek 2014년 12월 4일

10 개 추천

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

Konstantinos
Konstantinos 2014년 12월 4일
Thanks a lot!
Mahadi Hasan
Mahadi Hasan 2019년 4월 15일
thanks a lot brother.
Rajib Das
Rajib Das 2019년 9월 9일
Instead of specifying particular rows and columns can I specify range of rows and columms
Thanks
said mohamed
said mohamed 2021년 5월 5일
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)?

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

VANSHUL CHOUDHARY
VANSHUL CHOUDHARY 2021년 8월 20일

1 개 추천

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

Justin Paulan
Justin Paulan 2023년 11월 12일
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 2023년 11월 12일
@Justin Paulan, experiment with the methods shown in the Answers in this thread.
Ioannis Aggelos
Ioannis Aggelos 2024년 4월 29일
wow that was helpful (it wasnt)
Please note:
  1. 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]).
  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)]
A = 5×5
1.0000 2.0000 3.0000 4.0000 5.0000 -5.0000 -4.5000 -4.0000 -3.5000 -3.0000 0 1.0000 2.0000 3.0000 4.0000 10.0000 9.0000 8.0000 7.0000 6.0000 2.0000 4.0000 6.0000 8.0000 10.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
rows1 = [1, 2];
cols1 = [1, 2];
rows2 = [3, 4];
cols2 = [3, 4];
A4 = [A(rows1, cols1); A(rows2, cols2)]
A4 = 4×2
1.0000 2.0000 -5.0000 -4.5000 2.0000 3.0000 8.0000 7.0000
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>
@Ioannis Aggelos I hope this helps.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by