Plot checker board pattern where color of square is based on value of function.
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Image Analyst
2013년 3월 23일
편집: Image Analyst
2013년 3월 23일
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
Image Analyst
2013년 3월 24일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Modify Image Colors에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!