%% Display Slice Planes and Plot Streamlines
% This example shows how to use slice planes to create cross-sectional views of data, add contour plots to the slice planes, and plot stream lines.
%% Determine the Range of Coordinates
% Load the wind data set to get arrays x, y, z, u, v, and w. Determine the maximum and minimum values to locate the slice planes and contour plots.

load wind
xmin = min(x(:));
xmax = max(x(:));
ymax = max(y(:));
zmin = min(z(:));

%
%% Add Slice Planes
% Calculate the magnitude of the vector field, which represents the wind speed, to generate scalar data for the slice function.

wind_speed = sqrt(u.^2 + v.^2 + w.^2);

%
% Create slice planes along the x-axis at the values xmin, 100, and xmax. Locate them along the y-axis at ymax and along the z-axis at zmin. Specify interpolated face coloring so the slice coloring indicates wind speed. Set the EdgeColor of the slices to 'none' to draw them without edges.

figure
s = slice(x,y,z,wind_speed,[xmin,100,xmax],ymax,zmin);
set(s,'FaceColor','interp','EdgeColor','none')

%
%% Add Contour Lines to Slice Planes
% Draw contour lines on the slice planes. Store the patch handles created by contourslice as p. Set the edge color and the line width of the patches.

p = contourslice(x,y,z,wind_speed,[xmin,100,xmax],ymax,zmin);
set(p,'EdgeColor',[0.7,0.7,0.7],'LineWidth',0.5)

%
%% Add Stream Lines
% Plot streamlines starting from an x-value of 80. Plot the streamlines so that they span y-values between 20 and 50 and z-values between 0 and 15. Use thick red lines for the streamlines.

xspan = 80;
yspan = 20:10:50;
zspan = 0:5:15;
[sx,sy,sz] = meshgrid(xspan,yspan,zspan);
l = streamline(x,y,z,u,v,w,sx,sy,sz);
set(l,'LineWidth',2,'Color','r')

% Copyright 2015 The MathWorks, Inc.