Avoid squeeze of a matrix???
显示 更早的评论
Hi to all,
I face a problem with the handling of a 12 D matrix in matlab and I do not know if there is any more elegant solution... In particular, let's say that I have a matrix called "A" which is a 12D matrix and the size of this matrix is:
size(A)= 4096 1 1 8 1 1 1 1 1 1 1 124
For some reason I want to create a similar matrix called "B" with the last dim be the sum of the 124 elements of matrix A, B=sum(A,12) the problem then is that matlab squeezes the other dimensions which are equal to 1... so
size(B)= 4096 1 1 8
For the purposes of my application I want this matrix to be a 12D since this matrix is used by one other script and assumes that B is a 12D.
The solution that I found is
newSize =size(A)
newSize(12) =2
B= zeros (newSize)
and so on...
It works but it's really silly to have one additional dimension which is completely 0 and not be able to keep the 12Dim format of matrix B. Is there any other way to address this problem??
Thank you in advance for your suggestions guys.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!