changeset 56:ce90abc350c5

Added documentation to setup_1d_plot. Added updatableLine.m
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 12 Nov 2015 12:03:45 -0800
parents a8ed986fcf57
children 9a647dcccbdd
files +anim/setup_1d_plot.m +anim/updatableLine.m
diffstat 2 files changed, 27 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
diff -r a8ed986fcf57 -r ce90abc350c5 +anim/setup_1d_plot.m
--- a/+anim/setup_1d_plot.m	Thu Nov 12 09:47:04 2015 -0800
+++ b/+anim/setup_1d_plot.m	Thu Nov 12 12:03:45 2015 -0800
@@ -1,4 +1,15 @@
-function [update_data,plot_handles] = setup_1d_plot(x,y_lim,yfun)
+% Creates a plot and provides a function to update the data in it.
+%   x     - Vector of x-values to plot for.
+%   y_lim - 1x2 vector containing the y limits of the plot.
+%   yfun  - Function or a cell array of functions of y data vectors
+%           that should be plotted. The output of each function
+%           will be plotted to the same axis.
+%
+%   update_data(t,varargin) - Function to update plot data. All varargin will
+%                             be passed to functions in yfun.
+%   plot_handles            - Array of plot_handles. One for each yfun.
+%   axis_handle             - Handle to the axis plotted to.
+function [update_data, plot_handles, axis_handle] = setup_1d_plot(x,y_lim,yfun)
     default_arg('yfun',{@(y)y});
 
     if isa(yfun,'function_handle')
diff -r a8ed986fcf57 -r ce90abc350c5 +anim/updatableLine.m
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/+anim/updatableLine.m	Thu Nov 12 12:03:45 2015 -0800
@@ -0,0 +1,15 @@
+function [update_data, line_handle] = updatableLine()
+    figure_handle = gcf;
+    axis_handle = gca;
+
+    line_handle = line(0,0);
+
+    function update(x,y)
+        if ishandle(figure_handle) && ishandle(axis_handle)
+            set(line_handle,'XData',x);
+            set(line_handle,'YData',y);
+            drawnow
+        end
+    end
+    update_data = @update;
+end
\ No newline at end of file