# getting min and max for different y-values of a graph

1 view (last 30 days)
soloby on 23 Jun 2015
Commented: Walter Roberson on 25 Jun 2015
x = -10:0.1:10;
f1 = trapmf(x,[-2 0 0 2]);
I need to find min(x),max(x) for 201 different f1 values
since my f1 ranges from 0 to 1 in this built in function
@ f1 = 0, I need a min(x), max(x)
@ f1 = 0.05, min(x), max(x)
..
all the way upto
@f1 = 1, min(x), max(x).

Walter Roberson on 23 Jun 2015
testlocs = 0:0.05:1;
t = bsxfun(@ge, f1(:), testlocs);
for K = 1 : size(t, 1)
minidx = find(t(K,:), 1, 'first');
maxidx = find(t(K,:), 1, 'last');
minx(K) = testlocs(minidx);
maxx(K) = testlocs(maxidx);
end
soloby on 23 Jun 2015
i'm sorry I dont follow your coding, what is minx? it gives me a 1x201 matrix with all 0's.
Walter Roberson on 25 Jun 2015
testlocs = 0:0.05:1;
t = bsxfun(@le, testlocs(:), f1(:)');
for K = 1 : size(t, 1)
minidx = find(t(K,:), 1, 'first');
maxidx = find(t(K,:), 1, 'last');
minx(K) = testlocs(minidx);
maxx(K) = testlocs(maxidx);
end