looking for convenient way to extract matrix from 1*n*n
Mostrar comentarios más antiguos
Hi:
I have a 3*3*3 matrix, and I want to extract the data after its summation.
for example:
A=zeros(5,5,5)
B=sum(A,1);
now B is a 1*5*5 matrix, I want to assign it to a 5*5 matrix C but could not find a way, so looking for help here.
I tried
C=B(1,:,:)
but it does not work.
Thanks!
Respuesta aceptada
Más respuestas (2)
David Goodmanson
el 4 de Jun. de 2023
Editada: David Goodmanson
el 4 de Jun. de 2023
Hi YL,
A=zeros(5,5,5)
B=squeeze(sum(A,1));
Squeeze removes all singleton dimensions.
1 comentario
Yu Li
el 4 de Jun. de 2023
A = zeros(5,5,5)
B = permute(sum(A,1), [2 3 1]);
size(B)
squeeze() is a convenience function that ends up invoking permute(). squeeze() will not always give you the result you might expect:
C = squeeze(ones(1,1,5)), size(C)
Notice that squeeze() removed all of the singular dimensions, not just the first singular dimension.
1 comentario
Yu Li
el 4 de Jun. de 2023
Categorías
Más información sobre Resizing and Reshaping Matrices 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!