looking for convenient way to extract matrix from 1*n*n
2 views (last 30 days)
I have a 3*3*3 matrix, and I want to extract the data after its summation.
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.
but it does not work.
Ayush on 4 Jun 2023
You can use squeeze function here:
squeeze function removes all singleton dimensions. You can read more about them here.
It might interest you : Adding extra dimension
Now as, here we are squeezing the dimension, we can also add another dimension to already existing matrix.
Hope it helps.
More Answers (2)
Walter Roberson on 4 Jun 2023
A = zeros(5,5,5)
B = permute(sum(A,1), [2 3 1]);
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.