Plotting 4D with 3 vectors and 1 matrix
    7 views (last 30 days)
  
       Show older comments
    
    Simao Nobrega
 on 20 Jun 2015
  
    
    
    
    
    Commented: Simao Nobrega
 on 21 Jun 2015
            Hello,
I am solving a problem where I have three vectors (one for each 3D dimension), with different lengths and unevenly spaced, and a temperature matrix where each entry corresponds to the temperature at the position (x(i),y(j),z(k)). My goal is to make a 4D plot where the forth dimension (temperature) is represented my a colour (see attached file).
I have searched for an answer but did not get any solution for the conditions that I presented (3 vectors with 1 matrix). What function or approach would you recommend me to try?
*Data type*
length of x = M
length of y = N
length of z = P
size of Temperature matrix = M x N x P
Thanks in advance.

0 Comments
Accepted Answer
  Walter Roberson
      
      
 on 20 Jun 2015
        You can create a scattered interpolant and then sample it along grids. But as is hinted in your image, the outside is going to hide the inside when you plot. You can work with a voxel viewing routine or you can create isosurfaces to try to deal with that.
4 Comments
  Walter Roberson
      
      
 on 21 Jun 2015
				[X, Y, Z] = ndgrid(x, y, z);
slice(X, Y, Z, temperature, [min(x), max(x)], [min(y), max(y)], [min(z), max(z)], 'cubic')
More Answers (1)
  Hugo
      
 on 20 Jun 2015
        You could use "patch" since the surface will hide the interior points. You can create a matrix containing the coordinates of each point on the surface and then another matrix containing the indexes of the vertices defining each face in the patch. Suppose you want to create the faces corresponding to the top. You can use
xaux = repmat(x(:),1,Ny);
yaux = repmat(y(:)',Nx,1);
zaux = repmat(zval,Nx,Ny);
vertices = [xaux(:),yaux(:),zaux(:)];
faces = []; 
for indy = 1:Ny, 
for indx=1:Nx, 
faces=[faces;[indx,indx+1,indx+11,indx+10]+(indy-1)*10]; 
end, 
end
patch('Vertices',vertices,'Faces',faces,'CData',reshape(temperature(:,:,end),Nx*Ny,1),'FaceColor','interp','EdgeColor','none');
You will need to repeat this for each side. You can use any grid you want. The interpolation may be rather unsatisfactory. Hope this helps.
See Also
Categories
				Find more on Surface and Mesh Plots in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!