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.

 채택된 답변

Roger Stafford
Roger Stafford 2016년 5월 28일
M = [M(:,1:n);M(:,n+1:2*n);M(:,2*n+1:3*n)];

댓글 수: 4

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!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2016년 5월 28일

댓글:

2016년 5월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by