Skip to content

Commit

Permalink
minor updates
Browse files Browse the repository at this point in the history
  • Loading branch information
wschwanghart committed Feb 24, 2020
1 parent 48c09e9 commit 28aebe4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions @FLOWobj/upslopestats.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function OUT = upslopestats(FD,VAR,meth,S)

%UPSLOPESTATS upslope statistics of a variable based on the flow direction matrix
%UPSLOPESTATS upslope statistics computed in flow directions
%
% Syntax
%
Expand Down Expand Up @@ -139,14 +139,14 @@
ix = FD.ix;
ixc = FD.ixc;
% minimum imposition
for r = 1:numel(ix);
for r = 1:numel(ix)
VAR(ixc(r)) = min(VAR(ix(r)),VAR(ixc(r)));
end
case 'max'
ix = FD.ix;
ixc = FD.ixc;
% maximum imposition
for r = 1:numel(ix);
for r = 1:numel(ix)
VAR(ixc(r)) = max(VAR(ix(r)),VAR(ixc(r)));
end
end
Expand Down
18 changes: 13 additions & 5 deletions @GRIDobj/coord2ind.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
function [IX,res] = coord2ind(DEM,x,y)
function [IX,res,valid] = coord2ind(DEM,x,y)

%COORD2IND convert x and y coordinates to linear index
%
% Syntax
%
% IX = coord2ind(DEM,x,y)
% [IX,res] = ...
% [IX,res,valid] = ...
%
% Description
%
Expand All @@ -22,11 +23,13 @@
% ix linear index
% res residual distance between coordinates and nearest grid cell
% centers for coordinate pair x, y
% valid logical vector same size as x (or y) with true where x and y
% pairs are inside the grid, and otherwise false.
%
% See also: GRIDobj/ind2coord, GRIDobj/getcoordinates
%
% Author: Wolfgang Schwanghart (w.schwanghart[at]geo.uni-potsdam.de)
% Date: 17. August, 2017
% Date: 20. February, 2020



Expand All @@ -38,7 +41,7 @@

% check input
np = numel(x);
if np ~= numel(y);
if np ~= numel(y)
error('TopoToolbox:wronginput',...
'x and y must have the same number of elements.');
end
Expand All @@ -58,7 +61,7 @@

I = IX1>DEM.size(2) | IX1<1 | IX2>DEM.size(1) | IX2<1;

if any(I(:));
if any(I(:))
warning('TopoToolbox:outsidegrid',...
'There are some points outside the grid''s borders');
end
Expand All @@ -68,10 +71,15 @@

I = ~I;

if nargout == 3
valid = I;
end


if any(I)
IX = nan(np,1);
IX(I) = sub2ind(DEM.size,IX2(I),IX1(I));
if nargout == 2
if nargout >= 2
res = nan(np,1);
res(I) = hypot(X(IX1(I))-x,Y(IX2(I))-y);
end
Expand Down

0 comments on commit 28aebe4

Please sign in to comment.