How to divide a plot into different regions

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.

답변 (1개)

Image Analyst
Image Analyst 2013년 11월 4일

0 개 추천

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

Andy
Andy 2013년 11월 4일
Thank you, i don't think i made it too clear in my first post. The main problem i had was to plot the lines. For the image above i just used plot and specified the x and y values. That is not going to allow me to get all x and y values along that line, i would need some equation to create my line?
Image Analyst
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Annotations에 대해 자세히 알아보기

제품

질문:

2013년 11월 4일

편집:

2013년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by