Skip to content

Commit fa9bf01

Browse files
authored
Merge pull request #154 from wschwanghart/main
New function SWATHobj/applyfun and minor changes
2 parents 6f19897 + 4994548 commit fa9bf01

4 files changed

Lines changed: 1709 additions & 11 deletions

File tree

toolbox/@SWATHobj/applyfun.m

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
function [v,d,xy] = applyfun(SW,fun,A)
2+
3+
%APPLYFUN Apply function to extract values along swath
4+
%
5+
% Syntax
6+
%
7+
% [v,d] = applyfun(SW,fun)
8+
% [v,d] = applyfun(SW,fun,A)
9+
%
10+
% Description
11+
%
12+
% This functions applies a function fun to summarize/aggregate values
13+
% along the swath SW. fun must be a function that takes a 2D-matrix and
14+
% computes values along the first dimension of an array (e.g. @mean).
15+
% fun can also be a cell array of functions.
16+
%
17+
% Input arguments
18+
%
19+
% SW SWATHobj
20+
% fun function or character or cell array of function
21+
% A GRIDobj
22+
%
23+
% Output arguments
24+
%
25+
% v values mapped to trace
26+
% d distance along trace
27+
% xy trace coordinates
28+
%
29+
% Example
30+
%
31+
% DEM = GRIDobj('srtm_bigtujunga30m_utm11.tif');
32+
% x = [382209 389559]';
33+
% y = [3790773 3799443]';
34+
% SW = SWATHobj(DEM,x,y,'width',1000);
35+
% [v,d] = applyfun(SW,@(x) quantile(x,[.1:.1:.9]));
36+
% plot(d,v)
37+
%
38+
% See also: SWATHobj, SWATHobj/plotdz
39+
%
40+
% Author: Wolfgang Schwanghart (schwangh[at]uni-potsdam.de)
41+
% Date: 27. March, 2026
42+
43+
arguments
44+
SW SWATHobj
45+
fun
46+
A = []
47+
end
48+
49+
if ~isempty(A)
50+
SW = mapswath(SW,A);
51+
end
52+
53+
% Place function in cell array
54+
if ~iscell(fun)
55+
fun = {fun};
56+
end
57+
58+
% Iterate through cell array of functions
59+
for r = 1:numel(fun)
60+
% Convert string or character array to anonymous function
61+
if ischar(fun{r}) || isstring(fun{r})
62+
f = str2func(fun{r});
63+
else
64+
f = fun{r};
65+
end
66+
67+
if r == 1
68+
v = f(SW.Z);
69+
else
70+
v = vertcat(v,f(SW.Z)); %#ok<AGROW>
71+
end
72+
end
73+
74+
v = v';
75+
76+
if size(v,1) ~= size(SW.Z,2)
77+
error('TopoToolbox:error',...
78+
'Function output inconsistent with size of trace.')
79+
end
80+
d = SW.distx;
81+
xy = SW.xy;
82+
83+

toolbox/@SWATHobj/plot.m

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,25 +95,25 @@
9595
%
9696
%
9797
% Author: Dirk Scherler (scherler[at]gfz-potsdam.de)
98-
% Date: May, 2015
98+
% Date: March, 2026
9999

100100
arguments
101101
SW SWATHobj
102-
options.trace (1,1) = true
102+
options.trace (1,1) {mustBeFinite} = true
103103
options.tracecolor = 'k'
104-
options.outline (1,1) = true
104+
options.outline (1,1) {mustBeFinite} = true
105105
options.outlinecolor = 'k'
106-
options.points (1,1) = false
107-
options.left (1,1) = true
108-
options.right (1,1) = true
109-
options.legend (1,1) = true
106+
options.points (1,1) {mustBeFinite} = false
107+
options.left (1,1) {mustBeFinite} = true
108+
options.right (1,1) {mustBeFinite} = true
109+
options.legend (1,1) {mustBeFinite} = true
110110
options.labeldist {mustBeNumeric} = []
111111
options.plotmode {mustBeMember(options.plotmode,{'plot','scatter'})} = 'plot'
112-
options.colorz (1,1) = false
112+
options.colorz (1,1) {mustBeFinite} = false
113113
options.colormap = 'turbo'
114114
options.colorrange (1,2) = [-inf inf]
115115
options.colormode {mustBeMember(options.colormode,{'normal','inverse'})} = 'normal'
116-
options.colorbar (1,1) = true
116+
options.colorbar (1,1) {mustBeFinite} = true
117117
options.markersize (1,1) {mustBeNumeric,mustBePositive} = 2
118118
end
119119

toolbox/IOtools/readexample.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@
3333
% See also: GRIDobj, websave, readopentopo
3434
%
3535
% Author: Wolfgang Schwanghart (schwangh[at]uni-potsdam.de)
36-
% Date: 1. August, 2025
36+
% Date: 2. April, 2026
3737

3838
arguments
39-
example
39+
example {mustBeMember(example,{'taiwan','tibet','taalvolcano',...
40+
'kunashiri','perfectworld','kedarnath', ...
41+
'bigtujunga','greenriver'})}
4042
options.filename = fullfile(ttcachedir, strcat(example, '.tif'))
4143
options.deletefile (1,1) = false
4244
options.verbose (1,1) = true

0 commit comments

Comments
 (0)