| parameter counter if k<=numel(varargin)&&isscalar(varargin{k})&&ishandle(varargin{k})%re-use existing figurefig=varargin{k};tag=get(fig, 'Tag');assert(~isempty(tag)&&strcmp(tag, '__rtxiplot__'),...%verify figure tag 'rtxiplot:ArgumentTypeMismatch', 'An rtxiplot figure is expected.');k=k+1;elseif k<=numel(varargin)&&ischar(varargin{k})&&strcmp('new', varargin{k})%force creation of new figurefig=rtxiplot_figure();k=k+1;elsecurfig=get(0,'CurrentFigure');h=findobj('Type', 'figure', 'Tag', '__rtxiplot__');if isempty(h)%create new figure if no rtxiplot figure exists yetfig=rtxiplot_figure();setappdata(fig,'reset', 0);%do not reset listbox contentselseif isscalar(h)%a single rtxiplot figure existsif~isempty(curfig)&&h==curfig%currently active figure is an rtxiplot figurefig=curfig;elsefig=h;figure(fig);%currently active figure is not an rtxiplot figure, activate the only rtxiplot figureendelse%multiple rtxiplot figures existif~isempty(curfig)ix=find(h==curfig);%ix is either empty or a scalarelseix=[];endif isscalar(ix)%current figure is an rtxiplot figurefig=curfig;else%isempty(ix)fig=h(1);%use rtxiplot figure topmost in stacking orderfigure(fig);warning('rtxiplot:InvalidOperation',... 'Currently active figure is not an rtxiplot figure, the topmost rtxiplot figure has been activated.');endendendif k<=numel(varargin)&&ischar(varargin{k})%get channel names as captions for listboxcaption=varargin{k};k=k+1;else%use default captioncaption=[];endif k<=numel(varargin)&&isstruct(varargin{k})%get parametersparameters=varargin{k};k=k+1;else%use default captionparameters=[];endif k<=numel(varargin)&&isstruct(varargin{k})%get meta datameta=varargin{k};k=k+1;else%use default captionmeta=[];endsetappdata(fig,'meta', meta) if k > numel(varargin)%nothing to plotif~isempty(caption)warning('rtxiplot:InvalidOperation',... 'A caption is specified but no data to plot has been passed.');return;endreturn;endvarargin=varargin(k:end);%drop preprocessed argumentsppanel=findobj(fig,'Tag','parameterpanel');uicontrol(ppanel,... 'Style','text',... 'Units','normalized',... 'Position',[0.9 1 0.1],... 'String','INITIAL PARAMETERS');if(ischar(parameters.values{1}))%is stringpstr=['[{''', parameters.modelName{1},': ', parameters.parameterName{1},': ', parameters.values{1}];else%get the second value, the first is the timestamppstr=['[{''', parameters.modelName{1},': ', parameters.parameterName{1},': ', num2str(parameters.values{1}{1, 2})];end%pstr=['[{''', parameters.modelName{1},': ', parameters.parameterName{1},': ', num2str(parameters.values{1}{1, 2})];if size(parameters.values{1}, 1)>1pstr=[pstr,'*''}'];elsepstr=[pstr,'''}'];endfor p=2:length(parameters.parameterName)if(ischar(parameters.values{p}))%get stringpstr=[pstr,';{''', strrep(parameters.modelName{p},'''',''''''),': ', strrep(parameters.parameterName{p},'''',''''''),': ', parameters.values{p}];else%get the second value, the first is the timestamppstr=[pstr,';{''', strrep(parameters.modelName{p},'''',''''''),': ', strrep(parameters.parameterName{p},'''',''''''),': ', num2str(parameters.values{p}{1, 2})];end%pstr=[pstr,';{''', strrep(parameters.modelName{p},'''',''''''),': ', strrep(parameters.parameterName{p},'''',''''''),': ', num2str(parameters.values{p}{1, 2})];if size(parameters.values{p}, 1)>1pstr=[pstr,'*''}'];elsepstr=[pstr,'''}'];endendpstr=[pstr,']'];eval(['uicontrol(ppanel,''Style'',''text'',''Units'',''normalized'',''FontSize'', 9,''Position'',[.03 0 0.95 0.95],''HorizontalAlignment'',''Left'',''String'',', pstr,');']);listbox1=findobj(fig, 'Type', 'uicontrol', 'Tag', 'listbox1');string=get(listbox1, 'String');%cell array of all the item stringsif getappdata(fig,'reset')==1;userdata={};string={};set(listbox1,'Value', 1);elseuserdata=get(listbox1, 'UserData');endif numel(string) > 100warning('rtxiplot:InvalidOperation', 'There are too many plots, new plot has not been added.');return;endif numel(string)==1 &&strcmp(string, '[empty]')%there is only the placeholder item in the liststring={};%clear placeholder itemuserdata={};enduserdata{numel(userdata)+1}=varargin;%add arguments to plot functionif isempty(caption)caption=sprintf('Plot%d', numel(userdata));endstring{numel(string)+1}=caption;%add caption used in list boxset(listbox1,... 'String', string,... 'TooltipString', 'Double-click item(or hit ENTER) to plot in new figure window.',... 'UserData', userdata);if numel(string)<=1rtxiplot_onselectionchange(listbox1);%show first selection by defaultendlistbox2=findobj(fig, 'Type', 'uicontrol', 'Tag', 'listbox2');string=get(listbox2, 'String');if getappdata(fig,'reset')==1;userdata={};string={};set(listbox2,'Value', 1);elseuserdata=get(listbox2, 'UserData');endif numel(string) > 100warning('rtxiplot:InvalidOperation', 'There are too many plots, new plot has not been added.');return;endif numel(string)==1 &&strcmp(string, '[empty]')%there is only the placeholder item in the liststring={};%clear placeholder itemuserdata={};enduserdata{numel(userdata)+1}=varargin;%add arguments to plot functionif isempty(caption)caption=sprintf('Plot%d', numel(userdata));endstring{numel(string)+1}=caption;%add caption used in list boxset(listbox2,... 'String', string,... 'TooltipString', 'Double-click item(or hit ENTER) to plot in new figure window.',... 'UserData', userdata);if numel(string)<=1rtxiplot_onselectionchange(listbox2);%show first selection by defaultendsetappdata(fig,'reset', 0);function fig=rtxiplot_figure()%Creates a new rtxiplot figure.fig=figure(... 'Tag', '__rtxiplot__');%ensures that all necessary controls are presenttry%try to use uisplitter if available[leftpanel, rightpanel]=uisplitpane(fig,'DividerWidth', 2,'DividerLocation', 0.25,'Orientation','hor');[boxpanel, plotpanel]=uisplitpane(rightpanel,'DividerWidth', 2,'DividerLocation', 0.25,'Orientation','hor');[topbox, bottombox]=uisplitpane(boxpanel,'DividerWidth', 2,'DividerLocation', 0.5,'Orientation','vert');[topplot, bottomplot]=uisplitpane(plotpanel, 'DividerWidth', 2,'Orientation','vert');[bttnpanel, ppanel]=uisplitpane(leftpanel,'DividerWidth', 2,'DividerLocation', 0.1,'Orientation','vert');set(leftpanel,'Tag','leftpanel');set(ppanel,'Tag','parameterpanel');set(bttnpanel,'Tag','buttonpanel');set(rightpanel,'Tag','rightpanel');set(boxpanel,'Tag','leftpanel');set(plotpanel,'Tag','plotpanel');set(topbox,'Tag','topbox');set(bottombox,'tag','bottombox');set(bottomplot,'Tag','bottomplot');set(topplot,'Tag','topplot');catchmsgbox('Get uisplitter!');endprev_button=uicontrol(bttnpanel,'Style','pushbutton',... 'Units','normalized',... 'String','Prev',... 'Position',[0.03 0.15 0.4 0.8],... 'Callback',@prev_button_callback);next_button=uicontrol(bttnpanel,'Style','pushbutton',... 'Units','normalized',... 'String','Next',... 'Position',[0.5 0.15 0.4 0.8],... 'Callback',@next_button_callback);listbox1=uicontrol(topbox,...%allows selection of data to plot 'Style', 'listbox',... 'Units', 'normalized',... 'Position',[.03 0.03 0.95.95],... 'String',{'[empty]'},...%placeholder item 'Tag', 'listbox1',... 'Callback',@rtxiplot_onselectionchange);listbox2=uicontrol(bottombox,...%allows selection of data to plot 'Style', 'listbox',... 'Units', 'normalized',... 'Position',[0.03 0.03 0.95.95],... 'String',{'[empty]'},...%placeholder item 'Tag', 'listbox2',... 'Callback',@rtxiplot_onselectionchange);axes('Parent', topplot);axes('Parent', bottomplot);set(listbox2, 'UserData',{{}});%no plot arguments belong to placeholder itemset(listbox1, 'UserData',{{}});%no plot arguments belong to placeholder itemfunction rtxiplot_plot(ax, varargin)%Plots data in an rtxiplot figure with the specified plot arguments.%%Input arguments:%ax:%an axes handle graphics object%varargin(optional):%parameters to pass to the plot functionif nargin >=2tryplot(ax, varargin{:});xlabel(ax,'time(s)');catch medisp('plot function produces an error when passed parameters:');args=varargin(:);disp(args);rtxiplot_error(ax);rethrow(me);endelse%nothing to plotrtxiplot_hideaxes(ax);endfunction prev_button_callback(src, eventdata) fig=ancestor(src, 'figure');meta=getappdata(fig,'meta');if meta.trialNum-1 > |