| [19102] | 1 | Index: ../trunk-jpl/src/m/contrib/resultstomatrix.m | 
|---|
|  | 2 | =================================================================== | 
|---|
|  | 3 | --- ../trunk-jpl/src/m/contrib/resultstomatrix.m        (revision 19022) | 
|---|
|  | 4 | +++ ../trunk-jpl/src/m/contrib/resultstomatrix.m        (revision 19023) | 
|---|
|  | 5 | @@ -1,64 +0,0 @@ | 
|---|
|  | 6 | -function matrix=resultstomatrix(md,resultname,field,varargin) | 
|---|
|  | 7 | -%RESULTSTOMATRIX - go grab in the model results structure the vector results for each time step (which is not empty), | 
|---|
|  | 8 | -%                  and line them up in a matrix.  If time vector is provided, resample. | 
|---|
|  | 9 | -% | 
|---|
|  | 10 | -%   Usage: | 
|---|
|  | 11 | -%      matrix=resultstomatrix(model,solutioname,fieldname) | 
|---|
|  | 12 | -% | 
|---|
|  | 13 | -%   Available options: | 
|---|
|  | 14 | -%      - 'time'     : vector providing new time tags used to resample time | 
|---|
|  | 15 | -% | 
|---|
|  | 16 | -%   Example: | 
|---|
|  | 17 | -%      vel=resultstomatrix(md,'TransientSolution','Vel'); | 
|---|
|  | 18 | -%      vel=resultstomatrix(md,'TransientSolution','Vel','time',2008:1/12:2014); | 
|---|
|  | 19 | -% | 
|---|
|  | 20 | -%   See also MODEL  resample | 
|---|
|  | 21 | - | 
|---|
|  | 22 | - | 
|---|
|  | 23 | -       options=pairoptions(varargin{:}); | 
|---|
|  | 24 | - | 
|---|
|  | 25 | -       results=md.results.(resultname); | 
|---|
|  | 26 | - | 
|---|
|  | 27 | -       %first, figure out the size: | 
|---|
|  | 28 | -       count=0; | 
|---|
|  | 29 | -       nods=0; | 
|---|
|  | 30 | -       for i=1:length(results), | 
|---|
|  | 31 | -               if ~isempty(results(i).(field)), | 
|---|
|  | 32 | -                       count=count+1; | 
|---|
|  | 33 | -                       nods=size(results(i).(field),1); | 
|---|
|  | 34 | -               end | 
|---|
|  | 35 | -       end | 
|---|
|  | 36 | - | 
|---|
|  | 37 | -       if ~count, | 
|---|
|  | 38 | -               error(['could not find any result ' field ' in ' resultname]); | 
|---|
|  | 39 | -       end | 
|---|
|  | 40 | - | 
|---|
|  | 41 | -       %initialize: | 
|---|
|  | 42 | -       matrix=zeros(nods+1,count); | 
|---|
|  | 43 | - | 
|---|
|  | 44 | -       %fill it up: | 
|---|
|  | 45 | -       count=0; | 
|---|
|  | 46 | -       for i=1:length(results), | 
|---|
|  | 47 | -               if ~isempty(results(i).(field)), | 
|---|
|  | 48 | -                       count=count+1; | 
|---|
|  | 49 | -                       matrix(1:end-1,count)=results(i).(field); | 
|---|
|  | 50 | -                       matrix(end,count)=results(i).time/md.constants.yts; | 
|---|
|  | 51 | -               end | 
|---|
|  | 52 | -       end | 
|---|
|  | 53 | - | 
|---|
|  | 54 | -       newtime=getfieldvalue(options,'time',[]); | 
|---|
|  | 55 | -       newmatrix=zeros(nods+1,length(newtime)); | 
|---|
|  | 56 | -       if ~isempty(newtime), | 
|---|
|  | 57 | -               %we are asked to reinterpolate to this new time: | 
|---|
|  | 58 | - | 
|---|
|  | 59 | -               for i=1:nods, | 
|---|
|  | 60 | -                       warning off; | 
|---|
|  | 61 | -                       ts=timeseries(matrix(i,:), matrix(end,:)); | 
|---|
|  | 62 | -                       ts=resample(ts,newtime); | 
|---|
|  | 63 | -                       warning on; | 
|---|
|  | 64 | -                       newmatrix(i,:)=ts.Data; | 
|---|
|  | 65 | -                       newmatrix(end,:)=ts.Time; | 
|---|
|  | 66 | -               end | 
|---|
|  | 67 | - | 
|---|
|  | 68 | -               matrix=newmatrix; | 
|---|
|  | 69 | -       end | 
|---|
|  | 70 | Index: ../trunk-jpl/src/m/contrib/hack/resultstomatrix.m | 
|---|
|  | 71 | =================================================================== | 
|---|
|  | 72 | --- ../trunk-jpl/src/m/contrib/hack/resultstomatrix.m   (revision 0) | 
|---|
|  | 73 | +++ ../trunk-jpl/src/m/contrib/hack/resultstomatrix.m   (revision 19023) | 
|---|
|  | 74 | @@ -0,0 +1,64 @@ | 
|---|
|  | 75 | +function matrix=resultstomatrix(md,resultname,field,varargin) | 
|---|
|  | 76 | +%RESULTSTOMATRIX - go grab in the model results structure the vector results for each time step (which is not empty), | 
|---|
|  | 77 | +%                  and line them up in a matrix.  If time vector is provided, resample. | 
|---|
|  | 78 | +% | 
|---|
|  | 79 | +%   Usage: | 
|---|
|  | 80 | +%      matrix=resultstomatrix(model,solutioname,fieldname) | 
|---|
|  | 81 | +% | 
|---|
|  | 82 | +%   Available options: | 
|---|
|  | 83 | +%      - 'time'     : vector providing new time tags used to resample time | 
|---|
|  | 84 | +% | 
|---|
|  | 85 | +%   Example: | 
|---|
|  | 86 | +%      vel=resultstomatrix(md,'TransientSolution','Vel'); | 
|---|
|  | 87 | +%      vel=resultstomatrix(md,'TransientSolution','Vel','time',2008:1/12:2014); | 
|---|
|  | 88 | +% | 
|---|
|  | 89 | +%   See also MODEL  resample | 
|---|
|  | 90 | + | 
|---|
|  | 91 | + | 
|---|
|  | 92 | +       options=pairoptions(varargin{:}); | 
|---|
|  | 93 | + | 
|---|
|  | 94 | +       results=md.results.(resultname); | 
|---|
|  | 95 | + | 
|---|
|  | 96 | +       %first, figure out the size: | 
|---|
|  | 97 | +       count=0; | 
|---|
|  | 98 | +       nods=0; | 
|---|
|  | 99 | +       for i=1:length(results), | 
|---|
|  | 100 | +               if ~isempty(results(i).(field)), | 
|---|
|  | 101 | +                       count=count+1; | 
|---|
|  | 102 | +                       nods=size(results(i).(field),1); | 
|---|
|  | 103 | +               end | 
|---|
|  | 104 | +       end | 
|---|
|  | 105 | + | 
|---|
|  | 106 | +       if ~count, | 
|---|
|  | 107 | +               error(['could not find any result ' field ' in ' resultname]); | 
|---|
|  | 108 | +       end | 
|---|
|  | 109 | + | 
|---|
|  | 110 | +       %initialize: | 
|---|
|  | 111 | +       matrix=zeros(nods+1,count); | 
|---|
|  | 112 | + | 
|---|
|  | 113 | +       %fill it up: | 
|---|
|  | 114 | +       count=0; | 
|---|
|  | 115 | +       for i=1:length(results), | 
|---|
|  | 116 | +               if ~isempty(results(i).(field)), | 
|---|
|  | 117 | +                       count=count+1; | 
|---|
|  | 118 | +                       matrix(1:end-1,count)=results(i).(field); | 
|---|
|  | 119 | +                       matrix(end,count)=results(i).time/md.constants.yts; | 
|---|
|  | 120 | +               end | 
|---|
|  | 121 | +       end | 
|---|
|  | 122 | + | 
|---|
|  | 123 | +       newtime=getfieldvalue(options,'time',[]); | 
|---|
|  | 124 | +       newmatrix=zeros(nods+1,length(newtime)); | 
|---|
|  | 125 | +       if ~isempty(newtime), | 
|---|
|  | 126 | +               %we are asked to reinterpolate to this new time: | 
|---|
|  | 127 | + | 
|---|
|  | 128 | +               for i=1:nods, | 
|---|
|  | 129 | +                       warning off; | 
|---|
|  | 130 | +                       ts=timeseries(matrix(i,:), matrix(end,:)); | 
|---|
|  | 131 | +                       ts=resample(ts,newtime); | 
|---|
|  | 132 | +                       warning on; | 
|---|
|  | 133 | +                       newmatrix(i,:)=ts.Data; | 
|---|
|  | 134 | +                       newmatrix(end,:)=ts.Time; | 
|---|
|  | 135 | +               end | 
|---|
|  | 136 | + | 
|---|
|  | 137 | +               matrix=newmatrix; | 
|---|
|  | 138 | +       end | 
|---|