Mercurial > repos > public > sbplib
annotate +anim/setup_1d_plot.m @ 48:b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Thu, 05 Nov 2015 16:31:53 -0800 |
parents | 48b6fb693025 |
children | ce90abc350c5 |
rev | line source |
---|---|
48
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
1 function [update_data,plot_handles] = setup_1d_plot(x,y_lim,yfun) |
0 | 2 default_arg('yfun',{@(y)y}); |
3 | |
48
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
4 if isa(yfun,'function_handle') |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
5 yfun = {yfun}; |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
6 end |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
7 |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
8 figure_handle = gcf; |
0 | 9 plot_handles(1) = plot(x,0*x); |
10 hold on | |
11 for i = 2:length(yfun) | |
12 plot_handles(i) = plot(x,0*x); | |
13 end | |
14 hold off | |
15 | |
16 axis_handle = gca; | |
17 | |
18 xlabel('x') | |
19 ylabel('y') | |
20 xlim([x(1) x(end)]); | |
21 ylim(y_lim); | |
22 | |
23 function update(t,varargin) | |
24 if ishandle(figure_handle) && ishandle(axis_handle) | |
25 for i = 1:length(yfun) | |
26 set(plot_handles(i),'YData',yfun{i}(varargin{:})); | |
27 end | |
28 title(axis_handle,sprintf('T=%.3f',t)); | |
29 drawnow | |
30 end | |
31 end | |
32 update_data = @update; | |
33 end |