rbmatlab  1.16.09
 All Classes Namespaces Files Functions Variables Modules Pages
comsol_plot_sequence.m
1 function p = comsol_plot_sequence(varargin)
2 %function p = comsol_plot_sequence(varargin)
3 %
4 % This function was mainly copied from plot_sequence and adopted to special
5 % COMSOL usage. So please see the explanation there...
6 %
7 %
8 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %
11 %function p = plot_sequence(sim_data,params[,callbackfigure, cbhandle])
12 % plotting a sequence of data slices on polygonal
13 % 2d grid (constructed from params if empty) and providing a slider
14 % for changing between the data
15 % slices.
16 %
17 % A new figure is opened and the handle returned in p. If further parameters
18 % are set, the call is assumed to stem from a callback-function
19 %
20 % Every column of data is interpreted as one discrete function
21 % dof vector forwarded to the params.plot() function.
22 %
23 % parameters:
24 % varargin: usually called with 3 arguments:
25 % @code plot_sequence(data, grid, params) @endcode
26 % - data - data vector to be plotted
27 % - grid - the underlying grid
28 % - params - plotting parameters
29 % .
30 % Alternatively, there can be 5 arguments:
31 % @code plot_sequence(data, grid, params, callbackfigure, cbhandle) @endcode
32 % This function is set as a callback function for the time slider
33 % uicontrol. The additional arguments are:
34 % - callbackfigure - handle to the figure
35 % - cbhandle - handle to the object calling the callback function. This
36 % is usually the time slider.
37 %
38 % return values:
39 % p : figure handle of plot
40 %
41 % required fields in params:
42 % - 'plot' -- pointer to the plot-function performing the plotting of a
43 % single slice, e.g. plot_element_data(), plot_vertex_data(),
44 % fv_plot(), ldg_plot().
45 %
46 % optional field of params:
47 % - 'title' -- string indicating the title of the newly opened figure
48 % - 'clim' -- 2-vector giving the range of the colormap. If this is set,
49 % identical range is used for all slices. Default is the min and
50 % max of all slices.
51 % - 'clim_tight' -- if this flag is set, the colorbar is set tightly to the
52 % range of every single data slice. Clearly only one of
53 % 'clim' or 'clim_tight' should be set.
54 %
55 % see also the chosen 'params.plot_function' for its further params-options
56 %
57 % Bernard Haasdonk 9.5.2007
58 %
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
61 %
62 % Oliver Zeeb, 2013
63 
64 
65 
66 % open figure
67 if nargin < 3 % no callback, open new figure
68 
69  % keyboard;
70  f = figure;
71  di = 0.1;
72  textwidth= 0.15;
73  textheight = 0.05;
74  txt = uicontrol(f,'Style','text','Units','normalized',...
75  'Position',[di,di,textwidth,textheight],...
76  'String','Slice 1','Tag','text1');
77  slider = uicontrol(f,'Style','slider','Units','normalized',...
78  'Position',[di+textwidth+di, di ,1-3*di-textwidth,...
79  textheight],'Tag','slider1',...
80  'Callback','comsol_plot_sequence([],[],gcbf,gcbo)');
81  ax = axes('Units','normalized',...
82  'Position',[di,2*di+textheight,1-2*di,1-3*di - textheight],...
83  'Tag','axes1');
84 
85  ud = [];
86  ud.sim_data = varargin{1};
87  ud.params = varargin{2};
88 
89  set(f,'Userdata',ud);
90 
91  sl = findobj(f,'Tag','slider1');
92  %set(sl,'min',0);
93  %set(sl,'max',ud.params.nt);
94  %set(sl,'sliderstep',[1/ud.params.nt,1]);
95  set(sl,'min',1);
96  if size(ud.sim_data.U,2)>1
97  set(sl,'max',size(ud.sim_data.U,2));
98  set(sl,'sliderstep',[1/(size(ud.sim_data.U,2)-1),1]);
99  else
100  set(sl,'max',size(ud.sim_data.U,2)+eps);
101  set(sl,'visible','off');
102  % set(sl,'sliderstep',[0,0]);
103  end;
104  set(sl,'value',1);
105  th = findobj(f,'Tag','text1');
106  set(th,'String',('data slice 1') );
107  replot(f,sl,1);
108  % set(f,'Resize','on');
109  p = f;
110 end;
111 
112 if nargin >=3 % callback-function
113  cbf = varargin{3};
114  cbo = varargin{4};
115  th = findobj(gcbf,'Tag','text1');
116  v = round(get(gcbo,'value'));
117  set(gcbo,'value',v)
118  set(th,'String',['data slice ',num2str(v)]);
119  replot(gcbf,gcbo,v);
120  p = gcbf;
121 end;
122 
123 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124 function replot(fh,oh,v)
125 ud = get(fh,'Userdata');
126 
127 
128 ud.sim_data.comsol_model.result('pg1').set('solnum',v);
129 
130 ax = findobj(fh,'Tag','axes1');
131 cla(ax);
132 
133 mphplot(ud.sim_data.comsol_model,'pg1','rangenum',1)
134 
135 
136 
137 
138 
function p = plot_sequence(varargin)
plotting a sequence of data slices on polygonal 2d grid (constructed from params if empty) and provid...
Definition: plot_sequence.m:17