what is meant by singleton dimension?

 Accepted Answer

Image Analyst
Image Analyst on 5 Jul 2013
That's a dimension that has a length of 1. For example, if you had a 3D image that is 400 rows by 1 column by 200 slices, the second dimension (columns) would be a singleton since it's one. You'd have only one image plane running in the y-z direction (rows-slices). You can get back to a 2D image by using squeeze() to remove the singleton dimension.

4 Comments

is there any example of this?
Try this:
% Create a 3-D matrix with 2 rows, 4 columns, and 3 slices:
M3d = randi(9, 2, 4, 3)
% Extract slice 2. No singleton dimension since we're extracting the last index.
slice2 = M3d(:, :, 2) % Size is 2x4
whos slice2
% Extract slice that is essentially pulling the matrix
% that represents column 2 from the rectangular block.
% There will be a singleton dimension since we're NOT extracting the last index.
slice3 = M3d(:, 2, :) % Size is 2x1x3
whos slice3
% Run squeeze on slice 3 to get a 2x3 matrix, which is what you really wanted.
slice3a = squeeze(slice3)
whos slice3a
You get:
M3d(:,:,1) =
2 4 6 9
1 7 5 1
M3d(:,:,2) =
5 5 6 4
2 6 2 3
M3d(:,:,3) =
6 7 6 4
6 2 7 4
slice2 =
5 5 6 4
2 6 2 3
Name Size Bytes Class Attributes
slice2 2x4 64 double
slice3(:,:,1) =
4
7
slice3(:,:,2) =
5
6
slice3(:,:,3) =
7
2
Name Size Bytes Class Attributes
slice3 2x1x3 48 double
slice3a =
4 5 7
7 6 2
Name Size Bytes Class Attributes
slice3a 2x3 48 double
@Image Analyst
I've a doubt here, M3d = randi(9, 2, 4, 3)
What does '9' indicate in the above command?
That is the max value that the random numbers in the 2-by-4-by-3 three-D matrix can take on. Did you look up randi in the help documentation? It describes it there.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!