채택된 답변

Image Analyst
Image Analyst 2013년 7월 5일

10 개 추천

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

Minions
Minions 2020년 11월 16일
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
Swati Sarangi
Swati Sarangi 2020년 11월 20일
@Image Analyst
I've a doubt here, M3d = randi(9, 2, 4, 3)
What does '9' indicate in the above command?
Image Analyst
Image Analyst 2020년 11월 20일
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.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by