MATLAB: How to display specified slice as an image

mrimulti-dimensional arrays

Matlab has some data from an MRI scan built-in.
I can load it in 3 lines:
load mri; %load the sample data from Mathworks
D = double(squeeze(D));
D=D/max(D(:)); %Normalize to 0-1 range
So what I find that D has size 128 128 27
How can I write a function showslice(MRIdata, slice) that displays the specified slice as an image?

Best Answer

Try this
fontSize = 16;
load mri; %load the sample data from Mathworks
D = double(squeeze(D));
D=D/max(D(:)); %Normalize to 0-1 range
maxValue = max(D(:))
for k = 1 : size(D, 3)
thisSlice = D(:, :, k);
subplot(5, 6, k);
imshow(thisSlice, [0, maxValue]);
caption = sprintf('Slice #%d', k);
title(caption, 'FontSize', fontSize);
drawnow;
end