How to plot an empty 2-D cartesian grid on its own ?

Hello, I would like to plot a 2-D grid by itself as one figure with x ranging from 200-455 and y ranging from 50-305. Could someone please help.
PS: I only need to plot the grid, not any functions.

답변 (2개)

Stephen23
Stephen23 2019년 1월 17일
편집: Stephen23 2019년 1월 17일

3 개 추천

>> axes()
>> xlim([200,455])
>> ylim([50,305])
>> grid on
>> grid minor
Or alternatively in one axes call:
axes('XLim',[200,455], 'YLim',[50,305], 'XGrid','on', 'YGrid','on', 'XMinorGrid','on', 'YMinorGrid','on')
Gives:

댓글 수: 5

i want the grid plotted on the x and y axes from x=200 to 455 and y=50 to 305, not just display grid lines
Stephen23
Stephen23 2019년 1월 17일
편집: Stephen23 2019년 1월 17일
"i want the grid plotted on the x and y axes from x=200 to 455 and y=50 to 305, not just display grid lines"
It is not very clear what you want to achieve: do you want the grid lines to go from x=200 to x=455 with a step of 1? It seems that you actually want to control the tick mark locations (tick marks are the little marks perpendicular to the axes, usually where the tick labels are). This is easy to do, but I doubt that you will be happy with displaying 256 X tick marks and 256 Y tick marks and their associated grid lines:
>> axes('XLim',[200,455], 'YLim',[50,305], 'XTick',200:455, 'YTick',50:305, 'XGrid','on', 'YGrid','on')
Note how too many tick marks simply become incomprehensible. If that is not what you want then you will need to explain your need much clearer.
inspiration
inspiration 2019년 1월 17일
편집: inspiration 2019년 1월 17일
i actually want to plot a 2d grid on the cartesian coordinate system and the grid should be in the specified range. Later i have to plot a 2d and 3d sinc function on this grid. so first requirement is to plot the grid alone and the second requirement is to use the grid to plot the sinc functions in 2d and 3d. my prof had hinted to use mesh. i hope i made my question more clear.
Do you have a picture (not from MATLAB but from a textbook, webpage, or hand-drawn) that you can link to or can attach to a comment to show us exactly what you want? It's not clear to me what requirement you have that Stephen's suggestion fails to satisfy.
Stephen23
Stephen23 2019년 1월 17일
편집: Stephen23 2019년 1월 17일
"i actually want to plot a 2d grid on the cartesian coordinate system and the grid should be in the specified range."
And that is exactly what my answer and my comment have shown you:
  • my answer shows a grid with a step of ten, whereas
  • my previous comment shows a grid with a step of one.
They are both exactly over the range that you requested. If you really want to plot a grid yourself (rather than sensibly using the inbuilt grid capabilities) then you can do this quite easily using meshgrid, ndgrid, and line:
>> [X,Y] = meshgrid(200:455,50:305);
>> line(X,Y)
>> [X,Y] = ndgrid(200:455,50:305);
>> line(X,Y)
but I suspect that you will be quite disapppointed with that densely populated graphic. You could mess around with ismember and colon to try and get the grid lines where you want them, but there is little point as grid does it already. In any case, rather than making us guess what you want, please can you please show an image of exactly what you expect.

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

madhan ravi
madhan ravi 2019년 1월 17일
Perhaps?
[X,Y]=meshgrid(200:10:455,50:5:305);
mesh(X,Y)
view(2)

댓글 수: 2

this gives me a grid with origin(0,0) whereas i need the grid to be in the specified range of x and y. is there a way to do that?

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

카테고리

도움말 센터File Exchange에서 Polar Plots에 대해 자세히 알아보기

태그

질문:

2019년 1월 17일

편집:

2019년 1월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by