comparison scripts/plot/stairs.m @ 16752:d6b666e8449c

Update copies consistent subset of {x,y,z}data to children of the stairs hggoup. (Bug # 39234) * scripts/plot/stairs.m: When a listener for {x,y,z}data triggers an update, copy {x,y,z}data(1:M,1:N) to the hggroup's children, where M/N are the minimum number of rows/columns among the matrices, {x,y,z}data. Add demo.
author Ben Abbott <bpabbott@mac.com>
date Wed, 12 Jun 2013 20:25:36 +0800
parents c2dbdeaa25df
children 64e7bb01fce2
comparison
equal deleted inserted replaced
16751:92811d110839 16752:d6b666e8449c
231 %!demo 231 %!demo
232 %! clf; 232 %! clf;
233 %! [xs, ys] = stairs (9:-1:1); 233 %! [xs, ys] = stairs (9:-1:1);
234 %! plot (xs, ys); 234 %! plot (xs, ys);
235 235
236 %!demo
237 %! clf;
238 %! N = 11;
239 %! x = 0:(N-1);
240 %! y = rand (1, N);
241 %! hs = stairs (x(1), y(1));
242 %! set (gca (), 'xlim', [1, N-1], 'ylim', [0, 1]);
243 %! for k=2:N
244 %! set (hs, 'xdata', x(1:k), 'ydata', y(1:k))
245 %! drawnow ();
246 %! pause (0.2);
247 %! end
248
236 249
237 function update_props (h, d) 250 function update_props (h, d)
238 set (get (h, "children"), "color", get (h, "color"), 251 set (get (h, "children"), "color", get (h, "color"),
239 "linewidth", get (h, "linewidth"), 252 "linewidth", get (h, "linewidth"),
240 "linestyle", get (h, "linestyle"), 253 "linestyle", get (h, "linestyle"),
246 259
247 function update_data (h, d) 260 function update_data (h, d)
248 x = get (h, "xdata"); 261 x = get (h, "xdata");
249 y = get (h, "ydata"); 262 y = get (h, "ydata");
250 263
264 sz = min ([size(x); size(y)]);
265 x = x(1:sz(1), 1:sz(2));
266 y = y(1:sz(1), 1:sz(2));
267
251 nr = length (x); 268 nr = length (x);
252 len = 2 * nr - 1; 269 len = 2 * nr - 1;
253 xs = ys = zeros (1, len); 270 xs = ys = zeros (1, len);
254 271
255 xs(1) = x(1); 272 xs(1) = x(1);