MATLAB Answers

0

How could I extract the first two columns, and leave the next two and then so on from a matrix

Asked by Salman Ahmad on 5 Aug 2019
Latest activity Commented on by Salman Ahmad on 5 Aug 2019
for example I have 100 columns, then how could I extract the first two and then leave the next two columns like this (1,2,5,6,9,10,13,14,..............97,98)..

  0 Comments

Sign in to comment.

1 Answer

Answer by Joel Handy on 5 Aug 2019
Edited by Joel Handy on 5 Aug 2019
 Accepted Answer

% Set up example data set
A = eye(100);
A(1,:) = 1:100;
numCols = size(A,2);
% Answer
B = A(:,sort([1:4:numCols 2:4:numCols]));
% Verification
size(B)
B(1,:)

  1 Comment

Sign in to comment.