MATLAB Answers


How can I plot y-z plane slices in a 3D volume?

Asked by Nathan Lauer on 3 May 2016
Latest activity Commented on by AAKASH BANSAL on 30 Mar 2017
I have a series of plots representing the vorticity field behind an aircraft wing, at various downstream distances. Each is a 2D plot, and I would like to display them in 3D, one behind the other, in order to get a full 3D sense of the vorticity field behind the wing. In my first attempt, I made a 3D meshgrid, set it to zero, and filled in 4 z-slices with 4 vorticity plots, and that worked. However, I could not get it to the viewpoint that I wanted. Here is the plot that resulted:
This is rather confusing because in this plot, the wing is beneath the plot, and therefore is more likely to confuse the intended audience than do any good. Further, in attempting to change the viewing angle with Matlab's view command, I was not able to get to the desired viewing angle.
So then I made a second attempt, where instead of plotting z-slices I plot x-slices. This does indeed give me the desired viewing angle, as seen here (where the slices are just zeros):
Here, the wing is to the left of the plot, and it's much easier for the audience to get a sense of the full 3D vorticity field. However, I am unable to get the vorticity plots to display. Here is my code:
FullVectorField = zeros(200,14,13);
[x,y,z] = meshgrid(1:1:14, 1:1:200, 1:1:13);
FullVectorField(50,:,:) = vorticity70;
FullVectorField(100,:,:) = vorticity80;
FullVectorField(150,:,:) = vorticity90;
FullVectorField(200,:,:) = vorticity100;
zslice = [];
xslice = [50,100,150,200];
yslice = [];
A = FullVectorField(50,:,:);
pbaspect([3 1 1])
axis([0, 200, 0, 14, 0, 13])
colormap jet
xlabel('x axis (cm)')
ylabel('y axis (cm)')
zlabel('z axis (cm)')
vorticity70, vorticity80, etc are the matrices containing the data points I would like to plot. Any help in getting the vorticity plots to display along the xslices? Thanks!


Sign in to comment.

1 Answer

Answer by Mike Garrity
on 3 May 2016
Edited by Mike Garrity
on 3 May 2016
 Accepted Answer

You don't really need to build a full 3D array and then slice it. You can just place individual 2D slices in a 3D axes.
[y,z] = meshgrid(linspace(0,10,40));
for off=50:50:200
x = off + zeros(size(z));
% My standin for your vorticity data
c = cos((x+y)/5) .* cos((x+z)/5);
hold on
hold off
xlim([0 200])


Amazing, it worked perfectly, thank you!!
I have the same problem but my dataset is pixel intensity values between 1 to 255 for grayscale, when I plot using this code, I get completely black slices, any advice how to do this? :)

Sign in to comment.