Cici
Cici

Reputation: 1447

behavior of squeeze function in matlab

I am playing the squeeze function (matlab 2013b) and confused about it's behavior.

a(:,:,1)=[1 2 3];
a(:,:,2)=[4 5 6];
a(:,:,3)=[7 8 9];
a(:,:,4)=[10 11 12];
sa = squeeze(a);

b(:,:,1)=[1;2;3];
b(:,:,2)=[4;5;6];
b(:,:,3)=[7;8;9];
b(:,:,4)=[10;11;12];
sb=sqeeuze(b)

I would expect that sa to be 4*3 and sb to be 3*4, and sa being transpose(sb). Since each "layer" of a is a row vector, whereas each "layer" of b is a column vector. but, in fact sa is the same as sb.

Am I missing something here?

Upvotes: 1

Views: 4047

Answers (1)

Daniel
Daniel

Reputation: 36710

The definition of squeeze is very simple, remove singleton dimensions. The size of a is [1,3,4], removing singleton dimensions you get [3,4]. The size of b is [3,1,4], squeezing you get [3,4].

If squeeze does not what you want, take a look at reshape and permute

Upvotes: 3

Related Questions