How to divide a plot into different regions
조회 수: 11 (최근 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!