Thread Subject: Unapply "squeeze" function

Subject: Unapply "squeeze" function

From: Ida Haggstrom

Date: 20 Nov, 2008 09:23:02

Message: 1 of 2

Hi!
Something seem to have happened with my Matlab...
I'm working with 4D images of size (128,128,63,32), and when I pick out a certain 2D slice of the image stack,e.g. image(:,:,30,30), and check the size of the result, I used to get the answer (128,128,1,1). That is, I still kept the singleton dimensions. Now however, if I do the same thing I only get a 128x128 size, with the singleton dimensions removed by themselves. I haven't applied squeeze or anything...
The same thing happens if I do this:

size(zeros(128,128,1,1)) = [128 128]

when I switch the order though, it keeps singleton dimensions prior to multi-dimensions:

size(zeros(1,128,128,1)) = [1 128 128]

I want to keep the singleton dimensions, even if they are at the end of the matrix, and still pick out a 2D element from my 4D matrix. How can I do this? Thanks in advance! Cheers,
Ida

Subject: Unapply "squeeze" function

From: Loren Shure

Date: 20 Nov, 2008 13:10:24

Message: 2 of 2

In article <gg3a9m$mko$1@fred.mathworks.com>, ida_haggstrom@yahoo.se
says...
> Hi!
> Something seem to have happened with my Matlab...
> I'm working with 4D images of size (128,128,63,32), and when I pick out a certain 2D slice of the image stack,e.g. image(:,:,30,30), and check the size of the result, I used to get the answer (128,128,1,1). That is, I still kept the singleton dimensions. Now however, if I do the same thing I only get a 128x128 size, with the singleton dimensions removed by themselves. I haven't applied squeeze or anything...
> The same thing happens if I do this:
>
> size(zeros(128,128,1,1)) = [128 128]
>
> when I switch the order though, it keeps singleton dimensions prior to multi-dimensions:
>
> size(zeros(1,128,128,1)) = [1 128 128]
>
> I want to keep the singleton dimensions, even if they are at the end of the matrix, and still pick out a 2D element from my 4D matrix. How can I do this? Thanks in advance! Cheers,
> Ida
>

Explicitly you can't do this in MATLAB. Implicitly, every array in
MATLAB has an iinfinite number of trailing dimensions that aren't shown,
each with length 1.

Perhaps functions like cat, permute, shiftdim can help...

--
Loren
http://blogs.mathworks.com/loren

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
squeeze Ida Haggstrom 20 Nov, 2008 04:25:04
singleton dimen... Ida Haggstrom 20 Nov, 2008 04:25:04
rssFeed for this Thread

Contact us at files@mathworks.com