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.

 Akzeptierte Antwort

Roger Stafford
Roger Stafford am 28 Mai 2016
M = [M(:,1:n);M(:,n+1:2*n);M(:,2*n+1:3*n)];

4 Kommentare

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!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 28 Mai 2016

Kommentiert:

am 29 Mai 2016

Community Treasure Hunt

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

Start Hunting!

Translated by