Mercurial > repos > public > sbplib
annotate +anim/setup_1d_plot.m @ 87:0a29a60e0b21
In Curve: Rearranged for speed. arc_length_fun is now a property of Curve. If it is not supplied, it is computed via the derivative and spline fitting. Switching to the arc length parameterization is much faster now. The new stuff can be tested with testArcLength.m (which should be deleted after that).
author | Martin Almquist <martin.almquist@it.uu.se> |
---|---|
date | Sun, 29 Nov 2015 22:23:09 +0100 |
parents | f87003695677 |
children | a4e1608ae980 |
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)]); | |
30 ylim(y_lim); | |
31 | |
32 function update(t,varargin) | |
33 if ishandle(figure_handle) && ishandle(axis_handle) | |
34 for i = 1:length(yfun) | |
35 set(plot_handles(i),'YData',yfun{i}(varargin{:})); | |
36 end | |
37 title(axis_handle,sprintf('T=%.3f',t)); | |
38 end | |
39 end | |
40 update_data = @update; | |
41 end |