Plot points in xy-plane with different colours
Show older comments
I have a function implemented in MATLAB which for each point in [-2;2] x [-2;2] (i. e. for -2 ≤ x,y ≤ 2) returns exactly one of three possible outputs. I want to plot the function such that every point in this square is coloured in one of three different colours (for example red, blue or green), based on what the output of the function was. Of course, colouring every point is not possible, which is why I am specifying a width of the grid of points beforehand. My code looks like this:
for x = -2:width:2
for y = 2:-width:-2
%function f(x,y) with one of 3 different outputs here
if (f(x,y) = output 1) %colour point (x,y) green
if (f(x,y) = output 2) %colour point (x,y) red
if (f(x,y) = output 3) %colour point (x,y) blue
end
end
How can I implement this colouring? In the end, I want a plot of the xy-plane in the given area (including axes) with points in different colours based on the above procedure.
Additional question: The function is actually a fixed-point iteration which is stopped as soon as the result is closer to either output 1, 2 or 3 than a tolerance specified in advance. Is it possible to alter the "brightness" of the point in my plot based on how many steps the iteration takes to fulfill the break criterion?
Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!