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
MathWorks Support Team 2013 年 10 月 18 日
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 Center および File ExchangeMatrices and Arrays についてさらに検索

製品


リリース

R2006a

Community Treasure Hunt

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

Start Hunting!

Translated by