source: issm/trunk-jpl/src/m/contrib/resultstomatrix.m@ 19012

Last change on this file since 19012 was 19012, checked in by Eric.Larour, 10 years ago

NEW: new function resultstomatrix to extract results from md.results and to resample them in time.

File size: 1.6 KB
Line 
1function matrix=resultstomatrix(md,resultname,field,varargin)
2%RESULTSTOMATRIX - go grab in the model results structure the vector results for each time step (which is not empty),
3% and line them up in a matrix. If time vector is provided, resample.
4%
5% Usage:
6% matrix=resultstomatrix(model,solutioname,fieldname)
7%
8% Available options:
9% - 'time' : vector providing new time tags used to resample time
10%
11% Example:
12% vel=resultstomatrix(md,'TransientSolution','Vel');
13% vel=resultstomatrix(md,'TransientSolution','Vel','time',2008:1/12:2014);
14%
15% See also MODEL resample
16
17
18 options=pairoptions(varargin{:});
19
20 results=md.results.(resultname);
21
22 %first, figure out the size:
23 count=0;
24 nods=0;
25 for i=1:length(results),
26 if ~isempty(results(i).(field)),
27 count=count+1;
28 nods=size(results(i).(field),1);
29 end
30 end
31
32 if ~count,
33 error(['could not find any result ' field ' in ' resultname]);
34 end
35
36 %initialize:
37 matrix=zeros(nods+1,count);
38
39 %fill it up:
40 count=0;
41 for i=1:length(results),
42 if ~isempty(results(i).(field)),
43 count=count+1;
44 matrix(1:end-1,count)=results(i).(field);
45 matrix(end,count)=results(i).time/md.constants.yts;
46 end
47 end
48
49 newtime=getfieldvalue(options,'time',[]);
50 newmatrix=zeros(nods+1,length(newtime));
51 if ~isempty(newtime),
52 %we are asked to reinterpolate to this new time:
53
54 for i=1:nods,
55 warning off;
56 ts=timeseries(matrix(i,:), matrix(end,:));
57 ts=resample(ts,newtime);
58 warning on;
59 newmatrix(i,:)=ts.Data;
60 newmatrix(end,:)=ts.Time;
61 end
62
63 matrix=newmatrix;
64 end
Note: See TracBrowser for help on using the repository browser.