Mercurial > hg > octave-nkf
comparison scripts/plot/stairs.m @ 736:c8f88bd3202b
[project @ 1994-09-24 03:28:05 by jwe]
author | jwe |
---|---|
date | Sat, 24 Sep 1994 03:29:38 +0000 |
parents | 16a24e76d6e0 |
children | 3470f1e25a79 |
comparison
equal
deleted
inserted
replaced
735:7455048010b9 | 736:c8f88bd3202b |
---|---|
1 # Copyright (C) 1993 John W. Eaton | 1 # Copyright (C) 1993, 1994 John W. Eaton |
2 # | 2 # |
3 # This file is part of Octave. | 3 # This file is part of Octave. |
4 # | 4 # |
5 # Octave is free software; you can redistribute it and/or modify it | 5 # Octave is free software; you can redistribute it and/or modify it |
6 # under the terms of the GNU General Public License as published by the | 6 # under the terms of the GNU General Public License as published by the |
42 | 42 |
43 | 43 |
44 if (nargin == 1) | 44 if (nargin == 1) |
45 if (is_vector (x)) | 45 if (is_vector (x)) |
46 len = 2 * length (x); | 46 len = 2 * length (x); |
47 xs = ys = zeros (len, 1); | 47 tmp_xs = tmp_ys = zeros (len, 1); |
48 k = 0; | 48 k = 0; |
49 for i = 1:2:len | 49 for i = 1:2:len |
50 xs(i) = k++; | 50 tmp_xs(i) = k++; |
51 ys(i) = x(k); | 51 tmp_ys(i) = x(k); |
52 ys(i+1) = x(k); | 52 tmp_ys(i+1) = x(k); |
53 xs(i+1) = k; | 53 tmp_xs(i+1) = k; |
54 endfor | 54 endfor |
55 else | 55 else |
56 error ("stairs: argument must be a vector"); | 56 error ("stairs: argument must be a vector"); |
57 endif | 57 endif |
58 elseif (nargin == 2) | 58 elseif (nargin == 2) |
59 if (is_vector (x) && is_vector (y)) | 59 if (is_vector (x) && is_vector (y)) |
60 xlen = length (x); | 60 xlen = length (x); |
61 ylen = length (y); | 61 ylen = length (y); |
62 if (xlen == ylen) | 62 if (xlen == ylen) |
63 len = 2 * xlen; | 63 len = 2 * xlen; |
64 xs = ys = zeros (len, 1); | 64 tmp_xs = tmp_ys = zeros (len, 1); |
65 k = 1; | 65 k = 1; |
66 len_m2 = len - 2; | 66 len_m2 = len - 2; |
67 for i = 1:2:len_m2 | 67 for i = 1:2:len_m2 |
68 xs(i) = x(k); | 68 tmp_xs(i) = x(k); |
69 ys(i) = y(k); | 69 tmp_ys(i) = y(k); |
70 ys(i+1) = y(k); | 70 tmp_ys(i+1) = y(k); |
71 k++; | 71 k++; |
72 xs(i+1) = x(k); | 72 tmp_xs(i+1) = x(k); |
73 if (x(k) < x(k-1)) | 73 if (x(k) < x(k-1)) |
74 error ("stairs: x vector values must be in ascending order"); | 74 error ("stairs: x vector values must be in ascending order"); |
75 endif | 75 endif |
76 endfor | 76 endfor |
77 xs(len-1) = x(xlen); | 77 tmp_xs(len-1) = x(xlen); |
78 delta = x(xlen) - x(xlen-1); | 78 delta = x(xlen) - x(xlen-1); |
79 xs(len) = x(xlen) + delta; | 79 tmp_xs(len) = x(xlen) + delta; |
80 ys(len-1) = y(ylen); | 80 tmp_ys(len-1) = y(ylen); |
81 ys(len) = y(ylen); | 81 tmp_ys(len) = y(ylen); |
82 else | 82 else |
83 error ("stairs: arguments must be the same length"); | 83 error ("stairs: arguments must be the same length"); |
84 endif | 84 endif |
85 else | 85 else |
86 error ("stairs: arguments must be vectors"); | 86 error ("stairs: arguments must be vectors"); |
87 endif | 87 endif |
88 else | 88 else |
89 error ("usage: [xs, ys] = stairs (x, y)"); | 89 error ("usage: [xs, ys] = stairs (x, y)"); |
90 endif | 90 endif |
91 | 91 |
92 if (nargout == 1) | 92 if (nargout == 0) |
93 plot (xs, ys); | 93 plot (tmp_xs, tmp_ys); |
94 else | |
95 xs = tmp_xs; | |
96 ys = tmp_ys; | |
94 endif | 97 endif |
95 | 98 |
96 endfunction | 99 endfunction |