Mercurial > hg > octave-nkf
comparison scripts/plot/surface.m @ 7110:0e63f1126f01
[project @ 2007-11-06 22:36:22 by jwe]
author | jwe |
---|---|
date | Tue, 06 Nov 2007 22:36:22 +0000 |
parents | 5436efbf35e3 |
children | a67d30883ee0 |
comparison
equal
deleted
inserted
replaced
7109:5436efbf35e3 | 7110:0e63f1126f01 |
---|---|
1 | |
2 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, | 1 ## Copyright (C) 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2002, 2004, |
3 ## 2005, 2006, 2007 John W. Eaton | 2 ## 2005, 2006, 2007 John W. Eaton |
4 ## | 3 ## |
5 ## This file is part of Octave. | 4 ## This file is part of Octave. |
6 ## | 5 ## |
32 | 31 |
33 ## Author: jwe | 32 ## Author: jwe |
34 | 33 |
35 function h = surface (x, y, z, c) | 34 function h = surface (x, y, z, c) |
36 | 35 |
37 ax = gca(); | 36 ax = gca (); |
38 | 37 |
39 if (nargin == 1) | 38 if (nargin == 1) |
40 c = z = x; | 39 c = z = x; |
41 if (ismatrix (z)) | 40 if (ismatrix (z)) |
42 [nr, nc] = size (z); | 41 [nr, nc] = size (z); |
44 y = (1:nr)'; | 43 y = (1:nr)'; |
45 else | 44 else |
46 error ("surface: argument must be a matrix"); | 45 error ("surface: argument must be a matrix"); |
47 endif | 46 endif |
48 elseif (nargin == 3) | 47 elseif (nargin == 3) |
48 c = z; | |
49 if (isvector (x) && isvector (y) && ismatrix (z)) | 49 if (isvector (x) && isvector (y) && ismatrix (z)) |
50 if (rows (z) == length (y) && columns (z) == length (x)) | 50 if (rows (z) == length (y) && columns (z) == length (x)) |
51 x = x(:)'; | 51 x = x(:)'; |
52 y = y(:); | 52 y = y(:); |
53 else | 53 else |
54 msg = "surface: rows (z) must be the same as length (y) and"; | 54 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)"); |
55 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); | |
56 error (msg); | |
57 endif | 55 endif |
58 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | 56 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
59 if (! (size_equal (x, y) && size_equal (x, z))) | 57 if (! (size_equal (x, y) && size_equal (x, z))) |
60 error ("surface: x, y, and z must have same dimensions"); | 58 error ("surface: x, y, and z must have same dimensions"); |
61 endif | 59 endif |
62 c = z; | |
63 else | 60 else |
64 error ("surface: x and y must be vectors and z must be a matrix"); | 61 error ("surface: x and y must be vectors and z must be a matrix"); |
65 endif | 62 endif |
66 elseif (nargin == 4) | 63 elseif (nargin == 4) |
67 if !(size_equal (z, c)) | 64 if (! size_equal (z, c)) |
68 error ("surface: z and c must have same size"); | 65 error ("surface: z and c must have same size"); |
69 endif | 66 endif |
70 if (isvector (x) && isvector (y) && ismatrix (z)) | 67 if (isvector (x) && isvector (y) && ismatrix (z)) |
71 if (rows (z) == length (y) && columns (z) == length (x)) | 68 if (rows (z) == length (y) && columns (z) == length (x)) |
72 x = x(:)'; | 69 x = x(:)'; |
73 y = y(:); | 70 y = y(:); |
74 else | 71 else |
75 msg = "surface: rows (z) must be the same as length (y) and"; | 72 error ("surface: rows (z) must be the same as length (y) and columns (z) must be the same as length (x)" |
76 msg = sprintf ("%s\ncolumns (z) must be the same as length (x)", msg); | |
77 error (msg); | |
78 endif | 73 endif |
79 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) | 74 elseif (ismatrix (x) && ismatrix (y) && ismatrix (z)) |
80 if (! (size_equal (x, y) && size_equal (x, z))) | 75 if (! (size_equal (x, y) && size_equal (x, z))) |
81 error ("surface: x, y, and z must have same dimensions"); | 76 error ("surface: x, y, and z must have same dimensions"); |
82 endif | 77 endif |
85 endif | 80 endif |
86 else | 81 else |
87 print_usage (); | 82 print_usage (); |
88 endif | 83 endif |
89 | 84 |
90 ## make a default surface object | 85 ## Make a default surface object. |
91 tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); | 86 tmp = __go_surface__ (ax, "xdata", x, "ydata", y, "zdata", z, "cdata", c); |
92 | 87 |
93 set (ax, "view", [0, 90], "box", "off"); | 88 set (ax, "view", [0, 90], "box", "off"); |
94 set (tmp, "FaceColor","flat"); | 89 set (tmp, "facecolor","flat"); |
95 | 90 |
96 if (nargout > 0) | 91 if (nargout > 0) |
97 h = tmp; | 92 h = tmp; |
98 endif | 93 endif |
99 | 94 |