Plot checker board pattern where color of square is based on value of function.

4 visualizaciones (últimos 30 días)
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

Respuestas (1)

Image Analyst
Image Analyst el 23 de Mzo. de 2013
Editada: Image Analyst el 23 de Mzo. de 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 comentarios
Logan
Logan el 24 de Mzo. de 2013
Editada: Logan el 24 de Mzo. de 2013
This code is for an ecological model. J is the juvenile population, A is the adult population and N is the total population. I am discarding the first 1000 iterations because I want the system to settle into its long term behavior. My goal is to assign different colors for points that go extinction or 0, fall into an equilibrium ie N(t)=N(t+1), and periodic solutions. That is what the first if-elseif statements are for. It all works fine because the value of the variable color changes for successive iterations but it doesn't plot the colors. So for some reason the fill statements are faulty. I added a couple comments in the code to help make it easier to follow.
Image Analyst
Image Analyst el 24 de Mzo. de 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.

Iniciar sesión para comentar.

Community Treasure Hunt

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

Start Hunting!

Translated by