Plotting plain grid of size 100 X 100 AND selecting a "block" in the grid

조회 수: 11 (최근 30일)
I'm trying to plot a plain grid of a certain size. The regular " grid on " function gives me an automatic 1 X 1 grid.
I'm trying to plot a grid that is 100 X 100 and having each block a size of 1 X 1. This is what I have attempted so far:
x = (0:1:100)
y = (0:1:100)
fig1 = plot(x,x)
grid on
xlabel('x-axis')
ylabel('y-axis')
This is what it outputs
I'd like to output this grid without the line y=x showing up on it.
Also, I am trying to figure out how to select a specific block on the grid. I know that I can select a specific point on the grid but how would I be able to "shade in" an exact block on the grid.

채택된 답변

Star Strider
Star Strider 2017년 8월 31일
Try this:
figure(1)
plot([0:100; 0:100], [0:100; 0:100], 'k')
hold on
fill([0 1 1 0]+50, [0 0 1 1]+50, 'r') % Colour (50,50) Red
hold off
hax = gca;
hax.XTick = 0:100;
hax.YTick = 0:100;
hax.XTickLabel = [];
hax.YTickLabel = [];
grid
axis square
  댓글 수: 8
Star Strider
Star Strider 2017년 9월 1일
The ‘hax’ variable is the handle to the axes object created with the initial plot call. See the documentation on Axis Properties (link) for a full description.
The hold calls permit plotting more objects (here the fill call) on the same axes. I use ‘hold on’ and ‘hold off’ to keep track of the hold state. Without the ‘on’ and ‘off’ designators, hold simply toggles the hold state.
Evangelos Rompogiannakis
Evangelos Rompogiannakis 2020년 11월 18일
If i want to fill all the blocks where y < x how can i do it ??

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

KSSV
KSSV 2017년 8월 31일
편집: KSSV 2017년 8월 31일
x = (0:1:100) ;
y = (0:1:100) ;
% fig1 = plot(x,x)
[X,Y] = meshgrid(x,y) ;
mesh(X,Y,'edgecolor','k')
view(2)
grid on
xlabel('x-axis')
ylabel('y-axis')
  댓글 수: 2
Ammar Babikir
Ammar Babikir 2017년 8월 31일
I actually don't want any color on the grid. Would it be possible to just get that same grid that I had just without the line going through it?
KSSV
KSSV 2017년 8월 31일
You can set edgecolor property to black. Edited it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by