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

1 view (last 30 days)
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

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 18 Oct 2013
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.

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Products


Release

R2006a

Community Treasure Hunt

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

Start Hunting!