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

2 次查看(过去 30 天)
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).

回答(1 个)

Walter Roberson
Walter Roberson 2015-6-23
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
  2 个评论
soloby
soloby 2015-6-23
i'm sorry I dont follow your coding, what is minx? it gives me a 1x201 matrix with all 0's.
Walter Roberson
Walter Roberson 2015-6-25
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Elementary Math 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by