How to reshape any matrix using while loop or any other method?
Ältere Kommentare anzeigen
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.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 29 Jun. 2022
A = B(:, 1:6:end) ;
5 Kommentare
Sushil Pokharel
am 29 Jun. 2022
Walter Roberson
am 29 Jun. 2022
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
am 30 Jun. 2022
Bearbeitet: Sushil Pokharel
am 30 Jun. 2022
Kategorien
Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!