comparison +anim/setup_1d_plot.m @ 145:df83c8095326

setup 1d plot: Removed setting of axislabels. Made time in title optional.
author Jonatan Werpers <jonatan@werpers.com>
date Mon, 21 Mar 2016 16:23:24 +0100
parents 484b48e95c83
children
comparison
equal deleted inserted replaced
144:2fe13db674da 145:df83c8095326
7 % 7 %
8 % update_data(t,varargin) - Function to update plot data. All varargin will 8 % update_data(t,varargin) - Function to update plot data. All varargin will
9 % be passed to functions in yfun. 9 % be passed to functions in yfun.
10 % plot_handles - Array of plot_handles. One for each yfun. 10 % plot_handles - Array of plot_handles. One for each yfun.
11 % axis_handle - Handle to the axis plotted to. 11 % axis_handle - Handle to the axis plotted to.
12 function [update_data, plot_handles, axis_handle] = setup_1d_plot(x,yfun) 12 function [update_data, plot_handles, axis_handle] = setup_1d_plot(x,yfun,show_title)
13 default_arg('yfun',{@(y)y}); 13 default_arg('yfun',{@(y)y});
14 default_arg('show_title', true)
14 15
15 if isa(yfun,'function_handle') 16 if isa(yfun,'function_handle')
16 yfun = {yfun}; 17 yfun = {yfun};
17 end 18 end
18 19
22 plot_handles(i) = line(x,0*x); 23 plot_handles(i) = line(x,0*x);
23 end 24 end
24 25
25 axis_handle = gca; 26 axis_handle = gca;
26 27
27 xlabel('x')
28 ylabel('y')
29 xlim([x(1) x(end)]); 28 xlim([x(1) x(end)]);
30 29
31 function update(t,varargin) 30 function update(t,varargin)
32 if ishandle(figure_handle) && ishandle(axis_handle) 31 if ishandle(figure_handle) && ishandle(axis_handle)
33 for i = 1:length(yfun) 32 for i = 1:length(yfun)
34 set(plot_handles(i),'YData',yfun{i}(varargin{:})); 33 set(plot_handles(i),'YData',yfun{i}(varargin{:}));
35 end 34 end
36 title(axis_handle,sprintf('T=%.3f',t)); 35
36 if show_title
37 title(axis_handle,sprintf('T=%.3f',t));
38 end
37 end 39 end
38 end 40 end
39 update_data = @update; 41 update_data = @update;
40 end 42 end