comparison scripts/general/private/__splinen__.m @ 19833:9fc020886ae9

maint: Clean up m-files to follow Octave coding conventions. Try to trim long lines to < 80 chars. Use '##' for single line comments. Use '(...)' around tests for if/elseif/switch/while. Abut cell indexing operator '{' next to variable. Abut array indexing operator '(' next to variable. Use space between negation operator '!' and following expression. Use two newlines between endfunction and start of %!test or %!demo code. Remove unnecessary parens grouping between short-circuit operators. Remove stray extra spaces (typos) between variables and assignment operators. Remove stray extra spaces from ends of lines.
author Rik <rik@octave.org>
date Mon, 23 Feb 2015 14:54:39 -0800
parents 4197fc428c7d
children
comparison
equal deleted inserted replaced
19832:a1acca0c2216 19833:9fc020886ae9
26 ## FIXME: Allow arbitrary grids.. 26 ## FIXME: Allow arbitrary grids..
27 27
28 function yi = __splinen__ (x, y, xi, extrapval, f) 28 function yi = __splinen__ (x, y, xi, extrapval, f)
29 ## ND isvector function. 29 ## ND isvector function.
30 isvec = @(x) numel (x) == length (x); 30 isvec = @(x) numel (x) == length (x);
31 if (!iscell (x) || length (x) < ndims (y) || any (! cellfun (isvec, x)) 31 if (! iscell (x) || length (x) < ndims (y) || any (! cellfun (isvec, x))
32 || !iscell (xi) || length (xi) < ndims (y) || any (! cellfun (isvec, xi))) 32 || ! iscell (xi) || length (xi) < ndims (y)
33 || any (! cellfun (isvec, xi)))
33 error ("__splinen__: %s: non-gridded data or dimensions inconsistent", f); 34 error ("__splinen__: %s: non-gridded data or dimensions inconsistent", f);
34 endif 35 endif
35 yi = y; 36 yi = y;
36 for i = length (x):-1:1 37 for i = length (x):-1:1
37 yi = permute (spline (x{i}, yi, xi{i}(:)), [length(x),1:length(x)-1]); 38 yi = permute (spline (x{i}, yi, xi{i}(:)), [length(x),1:length(x)-1]);
38 endfor 39 endfor
39 40
40 [xi{:}] = ndgrid (cellfun (@(x) x(:), xi, "uniformoutput", false){:}); 41 [xi{:}] = ndgrid (cellfun (@(x) x(:), xi, "uniformoutput", false){:});
41 if (!isempty (extrapval)) 42 if (! isempty (extrapval))
42 idx = zeros (size (xi{1})); 43 idx = zeros (size (xi{1}));
43 for i = 1 : length (x) 44 for i = 1 : length (x)
44 idx |= xi{i} < min (x{i}(:)) | xi{i} > max (x{i}(:)); 45 idx |= xi{i} < min (x{i}(:)) | xi{i} > max (x{i}(:));
45 endfor 46 endfor
46 yi(idx) = extrapval; 47 yi(idx) = extrapval;