Why does the SQUEEZE function return the transpose of the expected output in MATLAB 7.2 (R2006a)?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
MathWorks Support Team
am 21 Jan. 2010
Bearbeitet: MathWorks Support Team
am 18 Dez. 2013
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
Akzeptierte Antwort
MathWorks Support Team
am 18 Okt. 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.
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!