Why does the SQUEEZE function return the transpose of the expected output in MATLAB 7.2 (R2006a)?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
MathWorks Support Team
le 21 Jan 2010
Modifié(e) : MathWorks Support Team
le 18 Déc 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
Réponse acceptée
MathWorks Support Team
le 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.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Matrices and Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!