MATLAB: Take lines from array matrix array I have an 64X4 array A , and I want take out every first 2 lines in every 4 line, is there some easy way to do that? Best Answer A = repmat([1 1 1 1; 2 2 2 2; 3 3 3 3; 4 4 4 4],16,1); % Example matrixB = zeros(32,4); % Preallocate BB(1:2:end) = A(1:4:end,:); % Take line 1 of every 4.th line in AB(2:2:end) = A(2:4:end,:); % Take line 2 of every 4.th line in Aresults in:A = 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4 1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4B = 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 1 1 1 1 2 2 2 2 Related SolutionsMATLAB: From a=[1 2 3 4] to b=[1 1 2 2 3 3 4 4] b = repelem(a,2) MATLAB: I have a data matrix each for 100 persons.Initially I was dividing columns into four segments (see code below). Now this data matrix vary, instead of 10000, the columns have different lengths. How can i divide them into 4 segments YOu can use reshape to achieve what you want.A = rand(100,3) ; % 100 rows of some data [nx,ny] = size(A) ;B = reshape(A',ny,[],4) ;iwant = permute(B,[2,1,3]); Related QuestionGenerating Array from nested loopsI want to traverse an array in an ‘inverse s’ order and store in a single row array is there any matlab function or code for this?eg[1 2 3; 3 4 5; 4 5 1] becomes [1,2,3,5,4,3,4,5,1]How can enlarge a matrixCan someone do this calculation without for loops
Best Answer