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.

 Respuesta aceptada

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

4 comentarios

Saeid
Saeid el 28 de Mayo de 2016
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.
Saeid
Saeid el 29 de Mayo de 2016
Awesome, exactly what I was looking for. Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 28 de Mayo de 2016

Comentada:

el 29 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by