Mercurial > hg > octave-lyh
comparison scripts/general/interpn.m @ 7208:a730e47fda4d
[project @ 2007-11-28 02:32:41 by jwe]
author | jwe |
---|---|
date | Wed, 28 Nov 2007 02:32:42 +0000 |
parents | 93c65f2a5668 |
children | 1c7b3e1fda19 c6c678875825 |
comparison
equal
deleted
inserted
replaced
7207:71c03c7239fb | 7208:a730e47fda4d |
---|---|
69 | 69 |
70 if (nargin < 1) | 70 if (nargin < 1) |
71 print_usage (); | 71 print_usage (); |
72 endif | 72 endif |
73 | 73 |
74 if (ischar (varargin {end})) | 74 if (ischar (varargin{end})) |
75 method = varargin {end}; | 75 method = varargin{end}; |
76 nargs = nargs - 1; | 76 nargs = nargs - 1; |
77 elseif (ischar (varargin {end - 1})) | 77 elseif (ischar (varargin{end - 1})) |
78 if (! isnumeric (varargin {end}) || ! isscalar (varargin {end})) | 78 if (! isnumeric (varargin{end}) || ! isscalar (varargin{end})) |
79 error ("extrapal is expected to be a numeric scalar"); | 79 error ("extrapal is expected to be a numeric scalar"); |
80 endif | 80 endif |
81 method = varargin {end - 1}; | 81 method = varargin{end - 1}; |
82 nargs = nargs - 2; | 82 nargs = nargs - 2; |
83 endif | 83 endif |
84 | 84 |
85 if (nargs < 3) | 85 if (nargs < 3) |
86 v = varargin {1}; | 86 v = varargin{1}; |
87 m = 1; | 87 m = 1; |
88 if (nargs == 2) | 88 if (nargs == 2) |
89 m = varargin {2}; | 89 m = varargin{2}; |
90 if (! isnumeric (m) || ! isscalar (m) || floor (m) != m) | 90 if (! isnumeric (m) || ! isscalar (m) || floor (m) != m) |
91 error ("m is expected to be a integer scalar"); | 91 error ("m is expected to be a integer scalar"); |
92 endif | 92 endif |
93 endif | 93 endif |
94 sz = size (v); | 94 sz = size (v); |
97 y = cell (1, nd); | 97 y = cell (1, nd); |
98 for i = 1 : nd; | 98 for i = 1 : nd; |
99 x{i} = 1 : sz(i); | 99 x{i} = 1 : sz(i); |
100 y{i} = 1 : (1 / (2 ^ m)) : sz(i); | 100 y{i} = 1 : (1 / (2 ^ m)) : sz(i); |
101 endfor | 101 endfor |
102 elseif (! isvector (varargin {1}) && nargs == (ndims (varargin {1}) + 1)) | 102 elseif (! isvector (varargin{1}) && nargs == (ndims (varargin{1}) + 1)) |
103 v = varargin {1}; | 103 v = varargin{1}; |
104 sz = size (v); | 104 sz = size (v); |
105 nd = ndims (v); | 105 nd = ndims (v); |
106 x = cell (1, nd); | 106 x = cell (1, nd); |
107 y = varargin (2 : nargs); | 107 y = varargin (2 : nargs); |
108 for i = 1 : nd; | 108 for i = 1 : nd; |
109 x{i} = 1 : sz(i); | 109 x{i} = 1 : sz(i); |
110 endfor | 110 endfor |
111 elseif (rem (nargs, 2) == 1 && nargs == | 111 elseif (rem (nargs, 2) == 1 && nargs == |
112 (2 * ndims (varargin {ceil (nargs / 2)})) + 1) | 112 (2 * ndims (varargin{ceil (nargs / 2)})) + 1) |
113 nv = ceil (nargs / 2); | 113 nv = ceil (nargs / 2); |
114 v = varargin {nv}; | 114 v = varargin{nv}; |
115 sz = size (v); | 115 sz = size (v); |
116 nd = ndims (v); | 116 nd = ndims (v); |
117 x = varargin (1 : (nv - 1)); | 117 x = varargin (1 : (nv - 1)); |
118 y = varargin ((nv + 1) : nargs); | 118 y = varargin ((nv + 1) : nargs); |
119 else | 119 else |
157 y{i} = y{i}(:); | 157 y{i} = y{i}(:); |
158 yidx{i} = lookup (x{i}(2:end-1), y{i}) + 1; | 158 yidx{i} = lookup (x{i}(2:end-1), y{i}) + 1; |
159 endfor | 159 endfor |
160 idx = cell (1,nd); | 160 idx = cell (1,nd); |
161 for i = 1 : nd | 161 for i = 1 : nd |
162 idx {i} = yidx{i} + (y{i} - x{i}(yidx{i}).' > ... | 162 idx{i} = yidx{i} + (y{i} - x{i}(yidx{i}).' > x{i}(yidx{i} + 1).' - y{i}); |
163 x{i}(yidx{i} + 1).' - y{i}); | |
164 endfor | 163 endfor |
165 vi = v (sub2ind (sz, idx{:})); | 164 vi = v (sub2ind (sz, idx{:})); |
166 idx = zeros (prod(yshape),1); | 165 idx = zeros (prod(yshape),1); |
167 for i = 1 : nd | 166 for i = 1 : nd |
168 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:)); | 167 idx |= y{i} < min (x{i}(:)) | y{i} > max (x{i}(:)); |