how to make grid lines closer in xaxis and y axis

3 visualizaciones (últimos 30 días)
moonman
moonman el 16 de Oct. de 2011
I have written this code
h1336=[];
L=50;
fs=8000;
fb=1336;
h1336 = (2/L)*cos(2*pi*fb*(0:L-1)/fs);
[H,F] = freqz(h1336,1,[],fs);
subplot(2,1,1)
plot(F./1000,20*log10(abs(H)));
grid on;
set(AX,'XMinorGrid','on')
xlabel('kHz'); ylabel('Magnitude-squared (dB)');
title('Magnitude Response of h1336 for L=50')
*
I want to have grid after every interval of .1 on xaxis and after every 1 on y-axis
how can i do this*
  1 comentario
Jan
Jan el 16 de Oct. de 2011
You code create the error "undefined Variable AX" in the "set(AX, ..." line. I assume you use "AX = subplot(2,1,1)"?

Iniciar sesión para comentar.

Respuesta aceptada

Jan
Jan el 16 de Oct. de 2011
XLimits = get(AX, 'Xlim');
YLimits = get(AX, 'Ylim');
set(AX, 'XTick', XLimits(1):0.1:XLimits(2), ...
'YTick', YLimits(1):1:YLimits(2));
It looks cruel.
  1 comentario
moonman
moonman el 16 de Oct. de 2011
Thanks a lot Jan and u rightly said, it look cruel
I will follow the instructions of Walter

Iniciar sesión para comentar.

Más respuestas (3)

Walter Roberson
Walter Roberson el 16 de Oct. de 2011
The only way to directly control the minor tick spacing on an axes is to draw the ticks in yourself (that is, by drawing lines in the positions you want the ticks to go.)
The documentation indicates that the number of minor ticks is determined automatically by the spacing of the major ticks. You can control the positions of the major ticks by setting XTick or YTick to a vector of values of where you want the ticks to be positioned. MATLAB might then happen to place the minor ticks where you want, but if it does not all you can do is draw them yourself.
When I encounter situations such as this, about the first thing I do is look at the File Exchange contribution plt which is much more flexible.
  1 comentario
moonman
moonman el 16 de Oct. de 2011
Thanks a lot Walter
I will follow what u said, it is easy to mark them by hand

Iniciar sesión para comentar.


moonman
moonman el 16 de Oct. de 2011
I am getting this error when i pasted ur code in my code
??? Undefined function or variable 'AX'.
  4 comentarios
Jan
Jan el 16 de Oct. de 2011
AX is undefined *and* has the value 173.0011?! Strange.
The numerical value seems to be a handle of a graphics object. This is an identification number, which allows to access the objects properties.
moonman
moonman el 16 de Oct. de 2011
I have defined the AX
AX=subplot(2,1,1)
Then i get the value 173.0011
does this number give any information

Iniciar sesión para comentar.


Walter Roberson
Walter Roberson el 16 de Oct. de 2011
Yes, the graphics handle number does give information, the information it gives is undocumented and completely subject to change between releases and even during the execution of any one program.
In the above case, the known information that it conveys is "this graphics object is most likely to be an axes". And that's about it, as far as anyone is willing to publicly admit.
The situation is about like going to a cafe' that offers take-out beverages in a variety of colorful paper cups, with the staff having arranged a pile of the cups near the latte machine, another pile near the coffee machine, and another pile near the tea machine. When the staff makes a take-out beverage, they grab the top cup on the pile nearest to where they are working. If a pile runs out and another pile is nearby, they use that instead until there is time to stock up more, which the staff does by grabbing another stack of cups from the bag.
You can see, if you think about such a situation, that the color of the cup used for any one beverage might change several times during a shift, and that there might be times when the tea pile is used for latte so no cup color is a promise, but if you were to ask a bunch of people what color of cup they got and what kind of beverage they got, then over the short term you could make good guesses about what kind of beverage people got by looking at the color of their cup.
Likewise, if you bother to study enough graphics handles, you will find that there are short-term correlations in the numbering that can hint about the kind of graphics object and about its likely relationship to other objects.
Is this information of any practical use? Probably not. But you only asked if it gave information, not if there was any value in the information. :)

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by