Creating Matrix Subset automatic.

조회 수: 10 (최근 30일)
Amit Chakraborty
Amit Chakraborty 2021년 9월 13일
댓글: Walter Roberson 2021년 9월 13일
I have a matrix, A which have a 9 row and 9 column. I need to make a subset from it.
The prospective subset we need : S1= [ 1 4 7] ; S2 =[2 5 8]; S3= [3 6 9]
Here S1 is telling that I need matrix that will take the element of 1st, 4th, 7th row of the matrix A and by doing vertical concatenation the matrix is perfectly formed.
I did like following which works perfect but I am wondering if my matrix is very large then is there any alternating way to that ? something like usiing some loops?
% Creating Matrix Subset
A=randi(9,9);
S1_a= A(1,:);
S1_b= A(4,:);
S1_c= A(7,:);
S1 = [S1_a; S1_b; S1_c] ; % Vertically concatenate

채택된 답변

Matt J
Matt J 2021년 9월 13일
편집: Matt J 2021년 9월 13일
You should be doing it as follows:
S=A([1,4,7],:);

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by