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!