7163
|
1 ## Copyright (C) 2007 Kai Habel |
|
2 ## |
|
3 ## This program is free software; you can redistribute it and/or modify it |
|
4 ## under the terms of the GNU General Public License as published by |
|
5 ## the Free Software Foundation; either version 2, or (at your option) |
|
6 ## any later version. |
|
7 ## |
|
8 ## OctPlot is distributed in the hope that it will be useful, but |
|
9 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
11 ## General Public License for more details. |
|
12 ## |
|
13 ## You should have received a copy of the GNU General Public License |
|
14 ## along with OctPlot; see the file COPYING. If not, write to the Free |
|
15 ## Software Foundation, 59 Temple Place - Suite 330, Boston, MA |
|
16 ## 02111-1307, USA. |
|
17 |
|
18 ## -*- texinfo -*- |
|
19 ## @deftypefn {Function File} ribbon (@var{X}, @var{Y}, @var{WIDTH}) |
|
20 ## @deftypefnx {Function File} ribbon (@var{X}, @var{Y}) |
|
21 ## @deftypefnx {Function File} ribbon (@var{Y}) |
|
22 ## @deftypefnx {Function File} @var{h} = ribbon (...) |
|
23 ## Plots ribbon plot for the columns of @var{Y} vs. @var{X}. The optional |
|
24 ## parameter @var{WIDTH} specifies the width of a single ribbon (default is 0.75). |
|
25 ## If @var{X} is omitted, a vector containing the row numbers is assumed (1:rows(Y)). |
|
26 ## If requested a vector @var{h} of the handles to the surface objects is returned. |
|
27 ## @end deftypefn |
|
28 ## @seealso{gca, colorbar} |
|
29 |
|
30 ## Author: Kai Habel <kai.habel at gmx.de> |
|
31 |
|
32 function h = ribbon(X, Y, W) |
|
33 |
|
34 newplot (); |
|
35 |
|
36 if (nargin == 1) |
|
37 Y = X; |
|
38 if (isvector(Y)) |
|
39 Y = Y(:); |
|
40 endif |
|
41 [nr, nc] = size(Y); |
|
42 X = repmat((1 : nr)', 1, nc); |
|
43 W = 0.75; |
|
44 elseif (nargin == 2) |
|
45 W = 0.75; |
|
46 elseif (nargin == 3) |
|
47 else |
|
48 print_usage(); |
|
49 end |
|
50 |
|
51 if (isvector(X) && isvector(Y)) |
|
52 if (length(X) != length(Y)) |
|
53 error("In case of vectors, X and Y must have same length") |
|
54 else |
|
55 [X, Y] = meshgrid(X, Y); |
|
56 endif |
|
57 else |
|
58 if (!all(size(X) == size(Y))) |
|
59 error("In case of matrices, X and Y must have same size") |
|
60 endif |
|
61 endif |
|
62 |
|
63 [nr,nc] = size(Y); |
|
64 tmp = zeros(1,nc); |
|
65 |
|
66 for c = nc:-1:1 |
|
67 ZZ = [Y(:,c) Y(:,c)]; |
|
68 y = X(:,c); |
|
69 x = [c - W / 2, c + W / 2]; |
|
70 [XX,YY] = meshgrid(x,y); |
|
71 CC = ones(size(ZZ))*c; |
|
72 tmp(c) = surface(XX,YY,ZZ,CC); |
|
73 endfor |
|
74 |
|
75 ax = get (tmp(c), "parent"); |
|
76 |
|
77 if (!ishold ()) |
|
78 set (ax, "view", [-37.5, 30], "box","off","xgrid","on","ygrid","on","zgrid","on"); |
|
79 endif |
|
80 |
|
81 if (nargout > 0) |
|
82 h = tmp; |
|
83 endif |
|
84 end |