grj 16/5/2013 The model parameter value gets concatonated along the first non-singleton dimension Inputs: models = a cell array of models to compare x = the independent variable modelvar = the field of the model to compare plotfunc = (optional) function handle for plotting the parameters Outputs: h = plot handle x = array of x values y = array of y values
0001 function [ h, x, y ] = plotmodels( models, x, modelvar, plotfunc ) 0002 % grj 16/5/2013 0003 %The model parameter value gets concatonated along the first non-singleton 0004 %dimension 0005 % 0006 %Inputs: 0007 % models = a cell array of models to compare 0008 % x = the independent variable 0009 % modelvar = the field of the model to compare 0010 %plotfunc = (optional) function handle for plotting the parameters 0011 % 0012 %Outputs: 0013 % h = plot handle 0014 % x = array of x values 0015 % y = array of y values 0016 0017 % Copyright (C) 2007-2013 Murphy Lab 0018 % Carnegie Mellon University 0019 % 0020 % This program is free software; you can redistribute it and/or modify 0021 % it under the terms of the GNU General Public License as published 0022 % by the Free Software Foundation; either version 2 of the License, 0023 % or (at your option) any later version. 0024 % 0025 % This program is distributed in the hope that it will be useful, but 0026 % WITHOUT ANY WARRANTY; without even the implied warranty of 0027 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0028 % General Public License for more details. 0029 % 0030 % You should have received a copy of the GNU General Public License 0031 % along with this program; if not, write to the Free Software 0032 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0033 % 02110-1301, USA. 0034 % 0035 % For additional information visit http://murphylab.web.cmu.edu or 0036 % send email to murphy@cmu.edu 0037 0038 0039 if ~exist('x', 'var') 0040 x = ones(1, length(models)); 0041 end 0042 0043 if iscell(models) 0044 models = [models{:}]; 0045 end 0046 0047 tokens = regexp(modelvar, '\.', 'split'); 0048 0049 %Get the data from each model 0050 for i = 1:length(models) 0051 model = models(i); 0052 for j = 1:length(tokens) 0053 model = model.(tokens{j}); 0054 end 0055 0056 y{i} = model; 0057 end 0058 0059 %Concationate data by the first singleton dimension 0060 ysize = size(y{1}); 0061 0062 inds = find(ysize ==1); 0063 0064 if isempty(inds) 0065 inds = length(ysize) +1; 0066 end 0067 0068 y = cat(inds(1), y{:}); 0069 0070 if exist('plotfunc', 'var') & ~isempty(plotfunc) 0071 h = plotfunc(x, y); 0072 else 0073 h = scatter(x,y); 0074 end 0075 0076 end