フィルターのクリア

Given the function of a line (linear), how can I get the number of occurrences that given points land above or below that line?

1 回表示 (過去 30 日間)
So, I'm working on a code that I know a line, let's say its in the form y=mx+b and its just y=x in this case (for simplicity). And I have a couple points that I want to know if they are above or below that line, doesnt matter.
I want the code to return an array like [abovecounts, belowcounts].
My initial thinking was to plug in the values for m and b, and then get a matrix of x and y values that go from like -10 to 10 or whatever, and then from there count the number of points that I plug in are above that. But mine is counting it for every x value. For example like I have y=x and I want to know if (0,1) is above it (which duh it is) but it counts it at every x value so I get a return of 10.
How can I define the line and then count the points once for above/below?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 29 日
編集済み: Ameer Hamza 2020 年 10 月 29 日
The method you described seems to be very inefficient and overkill to solve a very simple problem. Suppose you have a point (x1, y1). Just plug in the value of 'x1' in your equation y' = m*x1 + b. If the value of y1 > y', your point is above the line; otherwise, it is below the line.
For example
m = 1;
b = 0.1;
x = rand(10, 1);
y = rand(10, 1);
y_ = m*x+b;
mask = y > y_;
num_above_lines = sum(mask);
num_below_lines = sum(~mask);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAssembly についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by