
%%mm2601.m
t = linspace(0,10*pi);
plot3(sin(t),cos(t),t)
xlabel('sin(t)'), ylabel('cos(t)'), zlabel('t')
text(0,0,0,'Origin')
grid on
title('Figure 26.1: Helix')
v = axis

pause
%%mm2602.m
x = linspace(0,3*pi);  % x-axis data
z1 = sin(x);           % plot in x-z plane
z2 = sin(2*x);
z3 = sin(3*x);
y1 = zeros(size(x));   % spread out along y-axes
y3 = ones(size(x));    % by giving each curve different y-axis values
y2 = y3/2;
plot3(x,y1,z1,x,y2,z2,x,y3,z3)
grid on
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.2: sin(x), sin(2x), sin(3x)')
pause
plot3(x,z1,y1,x,z2,y2,x,z3,y3)
grid on
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.3: sin(x), sin(2x), sin(3x)')

pause
%%mm2603.m
x = linspace(0,3*pi);  % x-axis data
z1 = sin(x);           % plot in x-z plane
z2 = sin(2*x);
z3 = sin(3*x);
y1 = zeros(size(x));   % spread out along y-axes
y3 = ones(size(x));    % by giving each curve different y-axis values
y2 = y3/2;
plot3(x,z1,y1,x,z2,y2,x,z3,y3)
grid on
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.3: sin(x), sin(2x), sin(3x)')

pause
%%mm2604.m
[X,Y,Z] = peaks(30);
mesh(X,Y,Z)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.4: Mesh Plot of Peaks')

pause
%%mm2605.m
[X,Y,Z]=sphere(12);
subplot(1,2,1)
mesh(X,Y,Z), title('Figure 26.5a: Opaque')
hidden on
axis square off
subplot(1,2,2)
mesh(X,Y,Z), title('Figure 26.5b: Transparent')
hidden off
axis square off

pause
clf
%%mm2606.m
[X,Y,Z] = peaks(30);
meshc(X,Y,Z)  % mesh plot with underlying contour plot
title('Figure 26.6: Mesh Plot with Contours')

pause
%%mm2607.m
[X,Y,Z] = peaks(30);
meshz(X,Y,Z)  % mesh plot with zero plane
title('Figure 26.7: Mesh Plot with Zero Plane')


pause
%%mm2608.m
[X,Y,Z] = peaks(30);
waterfall(X,Y,Z)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.8: Waterfall Plot')

pause
%%mm2609.m
[X,Y,Z] = peaks(30);
surf(X,Y,Z)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.09: Surface Plot of Peaks')

pause
%%mm2610.m
[X,Y,Z] = peaks(30);
surf(X,Y,Z)  % same plot as above
shading flat
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.10: Surface Plot with Flat Shading')


pause
%%mm2611.m
[X,Y,Z] = peaks(30);
surf(X,Y,Z)  % same plot as above
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
shading interp
title('Figure 26.11: Surface Plot with Interpolated Shading')

pause
%%mm2612.m
[X,Y,Z] = peaks(30);
x = X(1,:);              % vector of x axis
y = Y(:,1);              % vector of y axis
i = find(y>.8 & y<1.2);  % find y axis indices of hole
j = find(x>-.6 & x<.5);  % find x axis indices of hole
Z(i,j) = nan;            % set values at hole indices to NaNs
surf(X,Y,Z)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.12: Surface Plot with a Hole')

pause
%%mm2613.m
[X,Y,Z] = peaks(30);
surfc(X,Y,Z)  % surf plot with contour plot
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.13: Surface Plot with Contours')

pause
%%mm2614.m
[X,Y,Z] = peaks(30);
surfl(X,Y,Z)    % surf plot with lighting
shading interp  % surfl plots look best with interp shading
colormap pink   % they also look better with shades of a single color
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.14: Surface Plot with Lighting')

pause
%%mm2615.m
[X,Y,Z] = peaks(15);
surfnorm(X,Y,Z)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.15: Surface Plot with Normals')

pause
%%mm2616.m
%x = rand(1,40);
%y = rand(1,40);
x=[0.95013      0.23114      0.60684      0.48598       0.8913       0.7621...
   0.45647     0.018504      0.82141       0.4447      0.61543      0.79194...
   0.92181      0.73821      0.17627      0.40571      0.93547       0.9169...
   0.41027      0.89365     0.057891      0.35287      0.81317    0.0098613...
   0.13889      0.20277      0.19872      0.60379      0.27219      0.19881...
   0.015274      0.74679       0.4451      0.93181      0.46599      0.41865...
   0.84622      0.52515      0.20265      0.67214];
y=[0.83812      0.01964      0.68128      0.37948       0.8318      0.50281...
   0.70947      0.42889      0.30462      0.18965      0.19343      0.68222...
   0.30276      0.54167      0.15087       0.6979      0.37837      0.86001...
   0.85366      0.59356      0.49655      0.89977      0.82163      0.64491...
   0.81797      0.66023      0.34197      0.28973      0.34119      0.53408...
   0.72711      0.30929       0.8385      0.56807      0.37041      0.70274...
   0.54657      0.44488      0.69457      0.62131];
z = peaks(x,y*pi);
t = delaunay(x,y);
trimesh(t,x,y,z)
hidden off
title('Figure 26.16: Triangular Mesh Plot')

pause
%%mm2617.m
%x = rand(1,40);
%y = rand(1,40);
x=[0.95013      0.23114      0.60684      0.48598       0.8913       0.7621...
   0.45647     0.018504      0.82141       0.4447      0.61543      0.79194...
   0.92181      0.73821      0.17627      0.40571      0.93547       0.9169...
   0.41027      0.89365     0.057891      0.35287      0.81317    0.0098613...
   0.13889      0.20277      0.19872      0.60379      0.27219      0.19881...
   0.015274      0.74679       0.4451      0.93181      0.46599      0.41865...
   0.84622      0.52515      0.20265      0.67214];
y=[0.83812      0.01964      0.68128      0.37948       0.8318      0.50281...
   0.70947      0.42889      0.30462      0.18965      0.19343      0.68222...
   0.30276      0.54167      0.15087       0.6979      0.37837      0.86001...
   0.85366      0.59356      0.49655      0.89977      0.82163      0.64491...
   0.81797      0.66023      0.34197      0.28973      0.34119      0.53408...
   0.72711      0.30929       0.8385      0.56807      0.37041      0.70274...
   0.54657      0.44488      0.69457      0.62131];
z = peaks(x,y*pi);
t = delaunay(x,y);
trisurf(t,x,y,z)
title('Figure 26.17: Triangular Surface Plot')



pause
%%mm2618.m
%x = rand(1,40);
%y = rand(1,40);
x=[0.95013      0.23114      0.60684      0.48598       0.8913       0.7621...
   0.45647     0.018504      0.82141       0.4447      0.61543      0.79194...
   0.92181      0.73821      0.17627      0.40571      0.93547       0.9169...
   0.41027      0.89365     0.057891      0.35287      0.81317    0.0098613...
   0.13889      0.20277      0.19872      0.60379      0.27219      0.19881...
   0.015274      0.74679       0.4451      0.93181      0.46599      0.41865...
   0.84622      0.52515      0.20265      0.67214];
y=[0.83812      0.01964      0.68128      0.37948       0.8318      0.50281...
   0.70947      0.42889      0.30462      0.18965      0.19343      0.68222...
   0.30276      0.54167      0.15087       0.6979      0.37837      0.86001...
   0.85366      0.59356      0.49655      0.89977      0.82163      0.64491...
   0.81797      0.66023      0.34197      0.28973      0.34119      0.53408...
   0.72711      0.30929       0.8385      0.56807      0.37041      0.70274...
   0.54657      0.44488      0.69457      0.62131];
z = peaks(x,y*pi);
t = delaunay(x,y);
voronoi(x,y,t)
title('Figure 26.18: Voronoi Plot')

pause
%%mm2619.m
x = -7.5:.5:7.5; y = x;   % create a data set
[X,Y] = meshgrid(x,y);
R = sqrt(X.^2+Y.^2)+eps;
Z = sin(R)./R;
subplot(2,2,1)
surf(X,Y,Z)
view(-37.5,30)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.19a: Default Az = -37.5, El = 30')
subplot(2,2,2)
surf(X,Y,Z)
view(-37.5+90,30)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.19b: Az Rotated to 52.5')
subplot(2,2,3)
surf(X,Y,Z)
view(-37.5,60)
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.19c: El Increased to 60')
subplot(2,2,4)
surf(X,Y,Z)
view(0,90)
xlabel('X-axis'), ylabel('Y-axis')
title('Figure 26.19d: Az = 0, El = 90')

pause
clf
%%mm2620.m
[X,Y,Z] = peaks;
contour(X,Y,Z,20)   % generate 20 2-D contour lines
xlabel('X-axis'), ylabel('Y-axis')
title('Figure 26.20: 2-D Contour Plot')

pause
%%mm2621.m
[X,Y,Z] = peaks;
contour3(X,Y,Z,20)  % the same contour plot in 3-D
xlabel('X-axis'), ylabel('Y-axis'), zlabel('Z-axis')
title('Figure 26.21: 3-D Contour Plot')

pause
%%mm2622.m
[X,Y,Z] = peaks;
pcolor(X,Y,Z)
shading interp  % remove the grid lines
title('Figure 26.22: Pseudocolor Plot')

pause
%%mm2623.m
[X,Y,Z] = peaks;
contourf(X,Y,Z,12) % filled contour plot with 12 contours
xlabel('X-axis'), ylabel('Y-axis')
title('Figure 26.23: Filled Contour Plot')

pause
%%mm2624.m
[X,Y,Z] = peaks;
C = contour(X,Y,Z,12);
clabel(C)
title('Figure 26.24: Contour Plot With Labels')

pause
%%mm2625.m
[X,Y,Z] = peaks;
[C,h] = contour(X,Y,Z,8); % ask for fewer contours
clabel(C,h)
title('Figure 26.25: Contour Plot With In-line Labels')

pause
%%mm2626.m
Z = peaks;
ribbon(Z)
title('Figure 26.26: Ribbon Plot of Peaks')

pause
%%mm2627.m
[X,Y,Z] = peaks(16);
[DX,DY] = gradient(Z,.5,.5);
contour(X,Y,Z,10)
hold on
quiver(X,Y,DX,DY)
hold off
title('Figure 26.27: 2-D Quiver Plot')

pause
%%mm2628.m
[X,Y,Z] = peaks(20);
[Nx,Ny,Nz] = surfnorm(X,Y,Z);
surf(X,Y,Z)
hold on
quiver3(X,Y,Z,Nx,Ny,Nz)
hold off
title('Figure 26.28: 3-D Quiver Plot')

pause
%%mm2629.m
fill3(rand(3,5),rand(3,5),rand(3,5),rand(3,5))
grid on
title('Figure 26.29: Five Random Filled Triangles')

pause
%%mm2630.m
Z = rand(5);
stem3(Z,'ro','filled');
grid on
title('Figure 26.30: Stem Plot of Random Data')

pause
%%mm2631.m
x=linspace(-3,3,13);
y=1:20;
z=-5:5;
[X,Y,Z]=meshgrid(x,y,z);
V=sqrt(X.^2 + cos(Y).^2 + Z.^2);
slice(X,Y,Z,V,[0 3],[5 15],[-3 5])
xlabel('X-axis')
ylabel('Y-axis')
zlabel('Z-axis')
title('Figure 26.31: Slice Plot Through a Volume')

pause
%%mm2632.m
x=linspace(-3,3,13);
y=1:20;
z=-5:5;
[X,Y,Z]=meshgrid(x,y,z);
V=sqrt(X.^2 + cos(Y).^2 + Z.^2);
[xs,ys]=meshgrid(x,y);
zs=sin(-xs+ys/2);
slice(X,Y,Z,V,xs,ys,zs)
xlabel('X-axis')
ylabel('Y-axis')
zlabel('Z-axis')
title('Figure 26.32: Slice Plot Using a Surface')

pause
%%mm2633.m
x=linspace(-3,3,13);
y=1:20;
z=-5:5;
[X,Y,Z]=meshgrid(x,y,z);
V=sqrt(X.^2 + cos(Y).^2 + Z.^2);
slice(X,Y,Z,V,[0 3],[5 15],[-3 5])
h=contourslice(X,Y,Z,V,3,[5 15],[]);
set(h,'EdgeColor','k','Linewidth',1.5)
xlabel('X-axis')
ylabel('Y-axis')
zlabel('Z-axis')
title('Figure 26.33: Slice Plot with Selected Contours')

pause
%%mm2634.m
[x,y,z,v] = flow(13);              % get flow data
fv = isosurface(x,y,z,v,-2);       % find surface of value -2
subplot(1,2,1)
p = patch(fv);                     % plot -2 surface
set(p,'FaceColor',[.5 .5 .5],'EdgeColor','Black'); % modify patches
view(3),axis equal tight, grid on  % pretty it up
title({'Figure 26.34a:' 'Isosurface Plot, V = 2'})
subplot(1,2,2)
p = patch(shrinkfaces(fv,.3));     % shrink faces to 30% of original 
set(p,'Facecolor',[.5 .5 .5],'EdgeColor','Black'); % modify patches
view(3),axis equal tight, grid on
title({'Figure 26.34a:' 'Shrunken Face Isosurface Plot, V = 2'})


pause
%%mm2635.m
[X,Y,Z,V] = flow;
fv = isosurface(X,Y,Z,V,-2);
subplot(2,2,1) % Original
p = patch(fv);
Np = size(get(p,'Faces'),1);
set(p,'FaceColor',[.5 .5 .5],'EdgeColor','Black');
view(3),axis equal tight, grid on  % pretty it up
zlabel(sprintf('%d Patches',Np))
title('Figure 26.35a: Original')

subplot(2,2,2) % Reduce Volume
[Xr,Yr,Zr,Vr] = reducevolume(X,Y,Z,V,[3 2 2]);
fvr = isosurface(Xr,Yr,Zr,Vr,-2);
p = patch(fvr);
Np = size(get(p,'Faces'),1);
set(p,'FaceColor',[.5 .5 .5],'EdgeColor','Black');
view(3),axis equal tight, grid on  % pretty it up
zlabel(sprintf('%d Patches',Np))
title('Figure 26.35b: Reduce Volume')

subplot(2,2,3) % Reduce Patch
p = patch(fv);
set(p,'FaceColor',[.5 .5 .5],'EdgeColor','Black');
view(3),axis equal tight, grid on  % pretty it up
reducepatch(p,.15) % keep 15 percent of the faces 
Np = size(get(p,'Faces'),1);
zlabel(sprintf('%d Patches',Np))
title('Figure 26.35c: Reduce Patches')

subplot(2,2,4) % Reduce Volume and Patch
p = patch(fvr);
set(p,'FaceColor',[.5 .5 .5],'EdgeColor','Black');
view(3),axis equal tight, grid on  % pretty it up
reducepatch(p,.15) % keep 15 percent of the faces 
Np = size(get(p,'Faces'),1);
zlabel(sprintf('%d Patches',Np))
title('Figure 26.35d: Reduce Both')


pause
%%mm2636.m
data = rand(10,10,10);         % random data
datas = smooth3(data,'box',3); % smoothed data

subplot(1,2,1) % random data
p = patch(isosurface(data,.5), ...
     'FaceColor','Blue','EdgeColor','none');
patch(isocaps(data,.5), ...
     'FaceColor', 'interp', 'EdgeColor', 'none');
isonormals(data,p)
view(3); axis vis3d tight off
camlight; lighting phong
title({'Figure 26.36a:' 'Random Data'})

subplot(1,2,2) % smoothed random data
p = patch(isosurface(datas,.5), ...
     'FaceColor','Blue','EdgeColor','none');
patch(isocaps(datas,.5), ...
     'FaceColor', 'interp', 'EdgeColor', 'none');
isonormals(datas,p)
view(3); axis vis3d tight off
camlight; lighting phong
title({'Figure 26.36a:' 'Smoothed Data'})

pause
%%mm2637.m
fstr=['3*(1-x).^2.*exp(-(x.^2) - (y+1).^2)' ... 
  ' - 10*(x/5 - x.^3 - y.^5).*exp(-x.^2-y.^2)' ... 
  ' - 1/3*exp(-(x+1).^2 - y.^2)'];
subplot(2,2,1)
ezmesh(fstr)
title('Figure 26.37a: Mesh of peaks(x,y)')
subplot(2,2,2)
ezsurf(fstr)
title('Figure 26.37b: Surf of peaks(x,y)')
subplot(2,2,3)
ezcontour(fstr)
title('Figure 26.37c: Contour of peaks(x,y)')
subplot(2,2,4)
ezcontourf(fstr)
title('Figure 26.37d: Contourf of peaks(x,y)')
