Why does the SQUEEZE function return the transpose of the expected output in MATLAB 7.2 (R2006a)?

1 次查看(过去 30 天)
I have created the following 3-D matrix:
Lb = zeros(4,3,3);
Lb(:,:,1) = [5 2 3
0 5 1
3 5 -2
2 2 -1];
Lb(:,:,2) = [ 3 0 6
4 -3 2
5 6 4
-4 2 2];
Lb(:,:,3) = [ 4 -5 4
7 2 3
4 -5 5
3 3 0];
When I execute the SQUEEZE function on the third frame of the variable Lb.
squeeze(LB(3,:,:))
I receive the following result:
3 5 4
5 6 -5
-2 4 5
However, I expect the following:
3 5 -2
5 6 4
4 -5 5
since
Lb(3,:,:) =
ans(:,:,1) =
3 5 -2
ans(:,:,2) =
5 6 4
ans(:,:,3) =
4 -5 5

采纳的回答

MathWorks Support Team
This is the expected behavior of the SQUEEZE function. MATLAB interprets a sequence of values as a column vector (because MATLAB matrices are stored column-wise in memory), and therefore will take the values in
Lb(3,:,1) =
3 5 -2
interpret them as a column vector. The same process occurs for Lb(3,:,2) and Lb(3,:,3). The three results are then put together in the resulting matrix:
3 5 4
5 6 -5
-2 4 5
To work around this issue, use the attached function, squeeze2.m, which will detect the size of the input matrix, and transpose the result from the SQUEEZE function accordingly.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

产品


版本

R2006a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by