How to reshape any matrix using while loop or any other method?
이전 댓글 표시
Hello there, I have a matrix B of size 432000x120 and I want another matrix A of same size in such a way that:
A(: , 1) = B(: , 1)
A(: , 2) = B(: , 7)
A(: , 3) = B(: , 13) and so on
I have done by using two for loops but I wanted to solve this problem by other method (may be by using while loop or any other efficient method). You help will be greatly appreciated.
채택된 답변
추가 답변 (1개)
Walter Roberson
2022년 6월 29일
A = B(:, 1:6:end) ;
댓글 수: 5
Sushil Pokharel
2022년 6월 29일
Walter Roberson
2022년 6월 29일
If you continue your sequence, you have A(:,20) = B(:,114) . What is to go into A(:,21) ?
%sample data
B = (1:36) + (1:5).'*100;
B
%the computation you need
A = reshape(permute(reshape(B, size(B,1), [], 6), [1 3 2]), size(B,1), []);
%display result
A
I don't think that works correctly when the number of columns is not 6^2:
B = (1:120) + (1:5).'*100;
A = reshape(permute(reshape(B, size(B,1), [], 6), [1 3 2]), size(B,1), [])
I guess it should be:
A = reshape(permute(reshape(B, size(B,1), [], size(B,2)/6), [1 3 2]), size(B,1), [])
Sushil Pokharel
2022년 6월 30일
편집: Sushil Pokharel
2022년 6월 30일
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!