Reputation: 45
I'm new to Matlab and I really need help with the following problem:
I have a 255 x 255 x 255 matrix and I would like to plot its 2D slices with imagesc().
I understand that for plotting slices parallel to the x, y, z planes I could just specify the slice with something like matrix(:,:,i), but how would I do that if I want to plot the x = y slice, or in general any x = n*y slice?
What I'm thinking is to interpolate the matrix to those planes and then extract the slice, but I'm a little stuck on how.
Specifically for the x = y slice I've been trying to build a 2D matrix by using the diag() command for each z slice and by setting the new_matrix = matrix(i,i,:) for i=1:255, but that didn't seem to be working.
Upvotes: 0
Views: 377
Reputation: 26069
for that Matlab gave you slice
!
[X,Y,Z] = meshgrid(-5:0.2:5);
V = X.*exp(-X.^2-Y.^2-Z.^2);
[xsurf,ysurf] = meshgrid(-2:0.2:2);
zsurf = xsurf/2+ysurf/2;
slice(X,Y,Z,V,xsurf,ysurf,zsurf)
and you can play with the camera view
angle to emulate the imagesc
feel, fir example try view(0, 90)
after the code I wrote...
By the way... if you insists on doing the cut and using imagesc the way you wanted, this is how with the example I gave:
for n=1:size(X,1)
D(:,n)=squeeze(V(n,n,:));
end
imagesc(D)
Upvotes: 3