Home > wafo > wstats > cplot.m

cplot

PURPOSE

Cubic plot of responses

h = cplot(y,D)

DESCRIPTION

 CPLOT Cubic plot of responses

CALL:  h = cplot(y,D);

y = responses
D = Design matrix

Example
D = ffd(3);
y = [60 72 54 68 52 83 45 80]; % Responses to design D.
cplot(y,D)

See also  ffd

CROSS-REFERENCE INFORMATION

This function calls:
 comnsize Check if all input arguments are either scalar or of common size. ffd Two-level Fractional Factorial Design axis Control axis scaling and appearance. error Display message and abort function. gca Get handle to current axis. hold Hold current graph. linspace Linearly spaced vector. num2str Convert number to string. (Fast version) plot Linear plot. plot3 Plot lines and points in 3-D space. set Set object properties. square Square wave generation. text Text annotation. xlabel X-axis label. ylabel Y-axis label. zlabel Z-axis label.
This function is called by:

SOURCE CODE

001 function h = cplot(y,D)
002 %CPLOT Cubic plot of responses
003 %
004 % CALL:  h = cplot(y,D);
005 %
006 %  y = responses
007 %  D = Design matrix
008 %
009 % Example
010 %   D = ffd(3);
011 %   y = [60 72 54 68 52 83 45 80]; % Responses to design D.
012 %   cplot(y,D)
013 %
015
016 error(nargchk(1,2,nargin))
017 sz = size(y);
018
019 n = length(y);
020
021 if n == prod(sz),
022   y = y(:);
023   n = length(y);
024 else
025   n = sz(1);
026 end
027
028 kmp = log2(n);
029 if nargin<2, D = ffd(kmp); end
030
031
032
033 [n1, k] = size(D);
034
035 if n~=n1, error('Something wrong'), end
036
037 p = k-kmp;
038
039
040 D(D<1)=-1;
041 r = 0.4;  % radius of circle
042 x2 = [-1+r 1-r ];
043 x1 = [-1 -1 ];
044 switch kmp
045   case 2, % 2D square plot
046       h1 = plot( x1,x2,'b',-x1,x2,'b',x2,x1,'b',x2,-x1,'b');
047       axis([-1 1 -1 1]*1.5)
048       set(gca,'xtick',-1:2:1,'ytick',-1:2:1,'Box','off')
049
050       h2 = text(D(:,1),D(:,2),num2str(y(:)),...
051       'HorizontalAlignment','center','VerticalAlignment','middle');
052       hold on,h3=circle2d(D(:,1),D(:,2),r,'b');,hold off
053
054   case 3, % 3D cubeplot
055     h1 = plot3( x1,x1,x2,'b',x1,-x1,x2,'b',-x1,x1,x2,'b',-x1,-x1,x2,'b');
056     hold on,
057     h11 = plot3(x1,x2,x1,'b',x1,x2,-x1,'b',-x1,x2,x1,'b',-x1,x2,-x1,'b');
058     h111 = plot3(x2,x1,x1,'b',x2,x1,-x1,'b',x2,-x1,x1,'b',x2,-x1,-x1,'b');
059     h1 = [h1;h11;h111];
060     axis([-1 1 -1 1 -1 1]*1.5)
061     set(gca,'xtick',-1:2:1,'ytick',-1:2:1,'ztick',-1:2:1,'Box','off')
062
063     h2 = text(D(:,1),D(:,2),D(:,3),num2str(y(:)),...
064     'HorizontalAlignment','center','VerticalAlignment','middle');
065     if 1,
066       h3=circle3d(D(:,1),D(:,2),D(:,3),r,'b');
067     else
068       h3 =[];
069     end
070     hold off
071     zlabel('C')
072   case 4, % 2D  cubeplot
073      h1 = plot( x1,x2,'b',-x1,x2,'b',x2,x1,'b',x2,-x1,'b');
074      x0 = 1; hold on
075      h1 = plot(x1+x0,x2+x0,'b',-x1+x0,x2+x0,'b',x2+x0,x1+x0,'b',x2+x0,-x1+x0,'b');
076      x3 = [-1+ r/sqrt(2)  -r/sqrt(2) ];
077      h1 = plot(x3,x3,'b',2*x0+x3,x3,'b',x3,2*x0+x3,'b',2*x0+x3,2*x0+x3,'b');
078
079       axis([-1 2 -1 2]*1.5)
080       set(gca,'xtick',-1:2:1,'ytick',-1:2:1,'Box','off')
081       ind1 = 1:4;
082       ind2 = 5:8;
083
084       h2 = text(D(ind1,1),D(ind1,2),num2str(y(ind1)),...
085       'HorizontalAlignment','center','VerticalAlignment','middle');
086       h2 = text(D(ind2,1)+x0,D(ind2,2)+x0,num2str(y(ind2)),...
087       'HorizontalAlignment','center','VerticalAlignment','middle');
088       h3=circle2d(D(ind1,1),D(ind1,2),r,'b');
089       h3=circle2d(x0+D(ind2,1),x0+D(ind2,2),r,'b');
090       hold off
091 end
092 xlabel('A')
093 ylabel('B')
094 axis square
095 if nargout>1,
096   h=[h1(:);h2(:);h3(:)];
097 end
098
099 function h = circle2d(x,y,r,varargin);
100   error(nargchk(2,inf,nargin))
101   if nargin<3,r=1;end
102   [ec, x,y,r]=comnsize(x,y,r);
103
104   n = length(x(:));
105   h = zeros(n,1);
106   th = linspace(0,2*pi,50)';
107   for ix=1:n,
108     h(ix) = plot(r(ix)*cos(th)+x(ix),r(ix)*sin(th)+y(ix),varargin{:});
109   end
110
111 return
112
113
114
115 function h = circle3d(x,y,z,r,varargin);
116   error(nargchk(3,inf,nargin))
117   if nargin<4,r=1;end
118   [ec, x,y,z,r]=comnsize(x,y,z,r);
119
120   n = length(x(:));
121   h = zeros(n,1);
122   m = 50;
123   th = linspace(0,2*pi,m)';
124   for ix=1:n,
125     h(ix) = plot3(r(ix)*cos(th)+x(ix),r(ix)*sin(th)+y(ix),repmat(z(ix),m,1));
126   end
127 return
128
129
130
131

Mathematical Statistics
Centre for Mathematical Sciences
Lund University with Lund Institute of Technology

Comments or corrections to the WAFO group

Generated on Thu 06-Oct-2005 02:21:16 for WAFO by m2html © 2003