File Exchange

image thumbnail

3D Volume Visualization

version (7.47 KB) by Joshua Stough
3D volume viz with interactive slice selection, colored ortho-planes, windowing, colormap selection.


Updated 23 Apr 2013

View Version History

View License

This tool provides an interactive 3D volume visualization. The function accepts as arguments any 3D matrix (of type double or uint8) and optional colormap, and displays a 2x2 figure of the 3 orthogonal planar views (neurological coordinate system) along with the built-in 'slice' visualization. Further, as you select slices through click and drag or scroll, the 3D view and color-coded orthogonal planes are updated accordingly. You may rotate the 3D view by manually selecting the 'Rotate 3D' figure button, and the 3D perspective (CameraPosition) is maintained as you continue changing slices.

This tool is more sparse than other volume visualizations out there, but it serves its purpose, and may offer an advantage with the added windowing and colormap selection capability.

Cite As

Joshua Stough (2021). 3D Volume Visualization (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (23)

Sarah Farthing

elnaz sadeghianfard

vis3d(seg, mycmap, figName)
Undefined function or variable 'mycmap'.
how fix this error?
plz help me

Quan Jiao

Monir Sh

Mohammad Saadatfar


very useful tool. very friendly for all 3D data visualisation. Thanks a lot!

Sebastiano Ferraris

Yasha Ali

Robert Schiessl

Jonas Reber

Reading your code's comments just made my day... love it! :D


Jonathan Boxshall

Hi Joshua,

Thanks very much for producing this tool, it's been very useful in allowing me to visualise radar data. To get around the couple of errors encountered, here's what I came up with:

Change str2num to str2double, seemed to work

Replaced whichView = find(cell2mat(handles) == gca);
with a for loop that seems to do the trick:
for ii=1:4
if handles{ii}==gca
I hope this helps anyone that was struggling with errrors like I was.


thanks for the work
im a beginner i matlab. i have 368, 512*512 ct images and i make a [512 512 368] .mat file.
how can i use this function?

Andreas Benedikter

Hi Joshua,
thanks for the work.

But I still get an error concerning the cell2mat.

"Error using cell2mat (line 52)
CELL2MAT does not support cell arrays containing cell arrays or objects.

Error in vis3d/buttonDownCallback (line 355)
whichView = find(cell2mat(handles) == gca);"

Do you have any advice how I can solve this Problem?



Excellent Work!


Hi Joshua,
I am using your code to visualize a large 3D matrix and it's working perfectly. However, in my project, I have to generate multiple 3D figures (more than 100) at a time and for this reason, I want to stop the figures which are being pop-up every iteration. Can you please tell me, how do I enable this feature? I have used "set(gcf,'Visible', 'off'): in my code. But it is not working.

Another question is, how do I save the figures in a directory in jpeg or other formats through Matlab script? I have used "saveas(a1,'myfig.jpg')" command, but it's also not working.


Yes there are some problems in the recent version of Matlab. Specifically with handling cells

Here is a way to make it work. Patches for the errors that Matlab encounters:

for i=1:length(myx) myx_aux=myx{i}; end
set(gca, 'XTickLabel', flippedx(str2num(myx_aux)));

for i =1:max(size(handles))
if(handles{i}==gca) whichView =i;

Don Catanzaro

When opening an 512x512x190 uint16 I get the following error:

Error using str2num (line 32)
Requires string or character array input.

Error in vis3d (line 272)
set(gca, 'XTickLabel', flippedx(str2num(myx)));


Abeera Tariq

Can someone help me that how to use this function if i have MxLxN matrix
where N is number of slices and MxL are 2D image slices.

Richard McCulloch

I used this tool for visualizing a 3D matrix of radiation particles. It worked pretty well. My results were more meaningful using colormap(jet), but that is an easy adjustment. (Just enter 'colormap(jet)' in the command window after opening the gui). Thank you, Joshua!

Joshua Stough

Response to Gustavo: My code doesn't care how you got the image. If it, say 'I', exists in matlab as a 3d array of any class (use size and class functions to determine this), then just try 'vis3d(double(I));' instead of whatever you were doing.

For loading nifti images, exchange #8797 seems popular:

Good luck,


Hi. I have started working with you toolboxes but i can't get any results. I have NIFTI images to work with. How can i adapt them to your toolbox?

Thanks in advance

MATLAB Release Compatibility
Created with R2012a
Compatible with any release
Platform Compatibility
Windows macOS Linux

Inspired by: OrthoView

Inspired: pcolor3, 4D Volume Visualization

Community Treasure Hunt

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

Start Hunting!