MATLAB: Efficient reordering of vector reordervector I would like to reorder vector as following: a = [1 2 3 4 5 6 7 8 9 10 11 12] to r = [1 5 9 2 6 10 3 7 11 4 8 12] what would be efficient way of doing so? Best Answer reshape( reshape(a, 4, 3).', 1, []) Related SolutionsMATLAB: Repeating blocks of N rows M times A = reshape(1:18,3.,[])';N=2;M=2;[~,n] = size(A);A2 = reshape(kron(reshape(A',n*N,[]),ones(1,M)),n,[])'; MATLAB: Reordering the data What about generating two random numbers as indices and swapping the data of the indices? And then do this in a loop.clcD=[1 2 3 4 5 6 7 ]for k=1:10 x1=randi(length(D)); x2=randi(length(D)); dummy=D(x1); D(x1)=D(x2); D(x2)=dummyend Related QuestionMatrix Elements Re-orderingHow to reshape a 2D to 3D matrix without using loops (reshape) and keeping a particular order of the elements// Wrong arragement of elemts after using “reshape”Index of reordered vectorArray rearrangementSparse matrix re-ordering
Best Answer