Plot checker board pattern where color of square is based on value of function.
3 views (last 30 days)
Show older comments
This is part of a larger process so I have rewritten the problem so that it can stand on its own. If something is unclear or looks off I would be happy to clarify or take a look at it again.
So what I am doing is taking a 100 points along the x and y axis and evaluating a function, f(x,y), on each point created by that grid. So if (1,1) gives a value that I associate with blue then I want the square with the corners (0,0),(0,1),(1,0) and (1,1) to be colored blue.
for x=1:X
for y=1:Y
if [Conditions on the value of f(x,y)]
color='blue'
elseif ...
...
else
...
end
% Here is what I tried for the plotting the figure. The figure opens and runs, but no colors are plotted so I something is off.
figure(1)
hold on
if x==1 && y~=1
fill(0,Y(y-1),X(x),Y(y-1),0,Y(y),X(x),Y(y),color)
elseif x~=1 && y==1
fill(X(x-1),0,X(x),0,X(x-1),Y(y),X(x),Y(y),color)
elseif i==1 && j==1
fill(0,0,X(x),0,0,Y(y),X(x),Y(y),color)
else
fill(X(x-1),Y(y-1),X(x),Y(y-1),X(x-1),Y(y),X(x),Y(y),color)
end
0 Comments
Answers (1)
Image Analyst
on 23 Mar 2013
Edited: Image Analyst
on 23 Mar 2013
I don't understand. You have
for x=1:X
and then in the fills you have X(x). Exactly what is capital X? If it's a 1D array of 100 values, then what are you doing in the "for" line? Can you give the values of X and Y so we can run your code? It's not quite standalone right now because it does run as given. I want to see the range of values that X takes on.
By the way, there is a checkerboard() function in the Image Processing Toolbox.
6 Comments
Image Analyst
on 24 Mar 2013
I don't have time to dive into the code and understand now. Maybe you can just use an image instead of the fill() function.
See Also
Categories
Find more on Annotations 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!