loop a matrix through disorder columns indices

조회 수: 1 (최근 30일)
Yousuf Khan
Yousuf Khan 2022년 7월 31일
답변: Abderrahim. B 2022년 7월 31일
I have a matrix A which has 100 rows and 5 columns, I would like to iterate the matrix with disorder indices of columns and save them in each iteration, column indices [2;5;3;4;1]. 1st iteration: get all the rows of A with column 2 then do some processes. 2nd iteration : get all the rows of A with columns 2 and 5. ..... last iteration: get all the rows and columns of A. Anyone helps me to implement it on Matlab environment please.

답변 (1개)

Abderrahim. B
Abderrahim. B 2022년 7월 31일
Hi!
What about this below!
% Dummy A
A = randi(4, 100, 5 ) ;
%
B = [] ;
for cIdx = [2 5 3 4 1]
B = [B, A(:, cIdx )]
end
B = 100×1
3 3 3 4 1 4 1 2 1 4
B = 100×2
3 2 3 3 3 3 4 4 1 1 4 3 1 4 2 1 1 3 4 3
B = 100×3
3 2 2 3 3 1 3 3 3 4 4 1 1 1 1 4 3 3 1 4 4 2 1 1 1 3 2 4 3 2
B = 100×4
3 2 2 1 3 3 1 2 3 3 3 4 4 4 1 2 1 1 1 2 4 3 3 2 1 4 4 2 2 1 1 2 1 3 2 2 4 3 2 3
B = 100×5
3 2 2 1 4 3 3 1 2 1 3 3 3 4 2 4 4 1 2 1 1 1 1 2 4 4 3 3 2 4 1 4 4 2 3 2 1 1 2 4 1 3 2 2 2 4 3 2 3 2

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by