Relocating entire blocks of matrix without using loop

Without using a "for" loop I need to relocate entire blocks of a matrix in the following manner:
This means vertically rearranging blocks that are placed horizontally next to each other, thereby creating a matrix with new dimensions, but the same number of elements.

 Réponse acceptée

M = [M(:,1:n);M(:,n+1:2*n);M(:,2*n+1:3*n)];

4 commentaires

Thanks Roger. Actually, I guess putting 3 as the number of times the blocks are repeated was a bit misleading in my presentation. What I meant was for the number of blocks to also be a deliberate value. Is there a way to relocate them now?
I thought you might make that change. Here is a general method:
M = reshape(permute(reshape(M,m,n,i),[1,3,2]),m*i,n);
Note: It is not a good idea to use 'i' as the name of your index, because it can be confused with matlab's reserved notation for the complex square root of -1.
Awesome, exactly what I was looking for. Thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by