How to reshape any matrix using while loop or any other method?
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 29 de Jun. de 2022
A = B(:, 1:6:end) ;
5 comentarios
Sushil Pokharel
el 29 de Jun. de 2022
Walter Roberson
el 29 de Jun. de 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
el 30 de Jun. de 2022
Editada: Sushil Pokharel
el 30 de Jun. de 2022
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!