How to divide a plot into different regions
6 ビュー (過去 30 日間)
古いコメントを表示
I have a random set of points which I intend to plot in different colours depending on their region. I am struggling on what function/equation i would need to create the lines/regions. An example of the regions i have plotted below. I would be looking to plot different colours in the 4 different regions i have quickly shown in the image below.

0 件のコメント
回答 (1 件)
Image Analyst
2013 年 11 月 4 日
Get the y values for each line for the x value of your point that you want to plot. So your point's y value will either be less than or greater than the y value of the line. For each line you will know if it's above or below, so just assign the color of the plot based on that.
if y < yBlackLine && y < yRedLine % y is the y of the point.
% Region 1. Plot point as red.
plot(x, y, 'ro');
elseif y < yBlackLine && y > yRedLine
% Region 2 Plot point as green.
plot(x, y, 'go');
elseif y > yBlackLine && y < yRedLine
% Region 3 Plot point as blue.
plot(x, y, 'bo');
elseif y > yBlackLine && y > yRedLine
% Region 4 Plot point as black
plot(x, y, 'ko');
end
2 件のコメント
Image Analyst
2013 年 11 月 4 日
編集済み: Image Analyst
2013 年 11 月 4 日
First, get the endpoints of the lines. Then plot them with line():
line([x1, x2], [y1, y2], 'Color', 'r');
Once you have that, you can calculate the slope
slope = (y2-y1) / (x2-x1);
Then the y value for any x value is
y = slope * (x-x1) + y1
Do that for both lines. Plug in the x value for the point you want to plot to find the y value for each line. Then determine if it's above or below the y value of the point you want to plot, like I showed.
参考
カテゴリ
Help Center および File Exchange で Annotations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!