]> Creatis software - CreaPhase.git/blob - octave_packages/ocs-0.1.3/utl/utl_plot_by_name.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / ocs-0.1.3 / utl / utl_plot_by_name.m
1 ## Copyright (C) 2006,2007,2008  Carlo de Falco            
2 ##
3 ## This file is part of:
4 ## OCS - A Circuit Simulator for Octave
5 ##
6 ## OCS is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation.
9 ##
10 ## This program is distributed in the hope that it will be useful,
11 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ## GNU General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with this program (see the file LICENSE); if not,
17 ## see <http://www.gnu.org/licenses/>.
18 ##
19 ## author: Carlo de Falco <cdf _AT_ users.sourceforge.net> 
20
21 ## -*- texinfo -*-
22 ## @deftypefn{Function File} {} utl_plot_by_name(@var{t},@var{out}, @
23 ## @var{outstruct},@var{namelist})
24 ##
25 ## Select by name some elements of the state vector of the system described
26 ## by @var{outstruct} and plot their dynamics over the time interval
27 ## @var{t}.  
28 ##
29 ## @var{namelist} should contain the list of names of the variables
30 ## to plot.
31 ## @var{out} should be the output of a transient simulation over the
32 ## time interval @var{t}
33 ##
34 ## @seealso{tst_backward_euler,tst_daspk,tst_theta_method,tst_odepkg,prs_iff}
35 ##
36 ## @end deftypefn
37
38 function utl_plot_by_name (t, out, outstruct, namelist)
39   
40   if (nargin != 4)
41     error ("utl_plot_by_name: wrong number of input parameters.")
42   endif
43
44   nn  = length (outstruct.namesn);
45   leg = {}; ileg = 0;
46   for ip = 1:nn
47     for in = 1:length (namelist)
48       if (strcmp (namelist{in},outstruct.namess{ip}))
49         plot (t, out(outstruct.namesn(ip), :), sprintf("%d", mod (in+1, 6) + 1));
50         leg{++ileg} = outstruct.namess{ip};
51         hold on
52       endif
53     endfor
54   endfor
55   legend (leg{:});
56
57   hold off
58
59 endfunction