How to divide a plot into different regions
8 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152834/image.png)
0 Kommentare
Antworten (1)
Image Analyst
am 4 Nov. 2013
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 Kommentare
Image Analyst
am 4 Nov. 2013
Bearbeitet: Image Analyst
am 4 Nov. 2013
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.
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!