title: How to plot a 3-Dimensional model with Matlab code
body: <p>I have 170 slices of 512 x 512 image in binary form (manual segmentation from a data set of medical images). 
  I would like to plot a 3 dimensional visualization/model of the object, by stacking these 170 slices of image together.</p>
  
  <p>I used concatenation function to stack all the 170 images into one matrix, D. My coding as below:</p>
  
  <pre><code>C = cell(1, 170);
  for k = 1:170;
      % Create a mat filename, and load it into a structure called matData.
      matFileName = sprintf('AAAmanual%d.mat', k);
      if exist(matFileName, 'file')
          load(matFileName);
          C{k} = BW;
      else
          fprintf('File %s does not exist.\n', matFileName);
      end
  end
  
  D = cat(3, C{:});
  </code></pre>
  
  <p>I'm not sure whether this is the correct way to do so. So i need your advice and help to proceed from here. How should i write in Matlab code, or what is the function suitable to use to visualize the model?</p>
  
  <p><img src="https://i.stack.imgur.com/lAhVd.jpg" alt="enter image description here"></p>
  
  <p>I got something plotted out using smoothed surface, but got an error mentioning out of memory. The coding for smoothed surface as follow:</p>
  
  <pre><code>patch(isocaps(D,.5),...
     'FaceColor','interp','EdgeColor','none');
  p1 = patch(isosurface(D,.5),...
     'FaceColor','blue','EdgeColor','none');
  isonormals(D,p1)
  view(3); 
  axis vis3d tight
  camlight left; 
  colormap jet
  lighting gouraud
  </code></pre>
  
  <p>Result from smooth3 plot:
  <img src="https://i.stack.imgur.com/Wsf5x.jpg" alt="enter image description here"></p>
  
  <p>How should i overcome the out of memory problem? or is there a better way to plot this?</p>