Mercurial > repos > public > sbplib
annotate +anim/setup_1d_plot.m @ 136:8298734b1938
Updated noname.calculateSolution to use the opt struct.
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Tue, 09 Feb 2016 13:27:38 +0100 |
parents | a4e1608ae980 |
children | 484b48e95c83 |
rev | line source |
---|---|
56
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
1 % Creates a plot and provides a function to update the data in it. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
2 % x - Vector of x-values to plot for. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
3 % y_lim - 1x2 vector containing the y limits of the plot. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
4 % yfun - Function or a cell array of functions of y data vectors |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
5 % that should be plotted. The output of each function |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
6 % will be plotted to the same axis. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
7 % |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
8 % update_data(t,varargin) - Function to update plot data. All varargin will |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
9 % be passed to functions in yfun. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
10 % plot_handles - Array of plot_handles. One for each yfun. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
11 % axis_handle - Handle to the axis plotted to. |
ce90abc350c5
Added documentation to setup_1d_plot. Added updatableLine.m
Jonatan Werpers <jonatan@werpers.com>
parents:
48
diff
changeset
|
12 function [update_data, plot_handles, axis_handle] = setup_1d_plot(x,y_lim,yfun) |
0 | 13 default_arg('yfun',{@(y)y}); |
14 | |
48
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
15 if isa(yfun,'function_handle') |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
16 yfun = {yfun}; |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
17 end |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
18 |
b21c53ff61d4
Made setup_1d_plot behave more like matlabs plot().
Jonatan Werpers <jonatan@werpers.com>
parents:
0
diff
changeset
|
19 figure_handle = gcf; |
0 | 20 plot_handles(1) = plot(x,0*x); |
21 for i = 2:length(yfun) | |
66
dbc50fa58ca6
Made setup_1d_plot behave like matlab plot.
Jonatan Werpers <jonatan@werpers.com>
parents:
56
diff
changeset
|
22 plot_handles(i) = line(x,0*x); |
0 | 23 end |
24 | |
25 axis_handle = gca; | |
26 | |
27 xlabel('x') | |
28 ylabel('y') | |
29 xlim([x(1) x(end)]); | |
113
a4e1608ae980
1d plot: Made it possible to have automatix axes.
Jonatan Werpers <jonatan@werpers.com>
parents:
69
diff
changeset
|
30 |
a4e1608ae980
1d plot: Made it possible to have automatix axes.
Jonatan Werpers <jonatan@werpers.com>
parents:
69
diff
changeset
|
31 if ~isempty(y_lim) |
a4e1608ae980
1d plot: Made it possible to have automatix axes.
Jonatan Werpers <jonatan@werpers.com>
parents:
69
diff
changeset
|
32 ylim(y_lim); |
a4e1608ae980
1d plot: Made it possible to have automatix axes.
Jonatan Werpers <jonatan@werpers.com>
parents:
69
diff
changeset
|
33 end |
0 | 34 |
35 function update(t,varargin) | |
36 if ishandle(figure_handle) && ishandle(axis_handle) | |
37 for i = 1:length(yfun) | |
38 set(plot_handles(i),'YData',yfun{i}(varargin{:})); | |
39 end | |
40 title(axis_handle,sprintf('T=%.3f',t)); | |
41 end | |
42 end | |
43 update_data = @update; | |
44 end |