フィルターのクリア

How do I change Grid Size in R2013a?

13 ビュー (過去 30 日間)
Edgar
Edgar 2014 年 3 月 8 日
コメント済み: Walter Roberson 2024 年 6 月 18 日
How do I change or adjust the grid size? I am suppose to have a grid of .001 for x values less than 2. How would I go about doing that? This is my code for my graph
x = (0:2*pi);
y = sin(x);
fig1 = plot(x,y)
fig1 =
Line with properties: Color: [0 0.4470 0.7410] LineStyle: '-' LineWidth: 0.5000 Marker: 'none' MarkerSize: 6 MarkerFaceColor: 'none' XData: [0 1 2 3 4 5 6] YData: [0 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.2794] Use GET to show all properties
grid on
xlabel('x-axis')
ylabel('y-axis')
  3 件のコメント
Sakthivel
Sakthivel 2024 年 6 月 18 日
Is the plot correct when the grid size is 5?
Walter Roberson
Walter Roberson 2024 年 6 月 18 日
Yes, the plot is correct when the grid size is 5. It just isn't very interesting.
x = (0:2*pi);
uses the default increment of 1 for the list of values. The resulting x will have only 0, 1, 2, 3, 4, 5, and 6. That is not dense enough for a meaningful plot.

サインインしてコメントする。

採用された回答

Sven
Sven 2014 年 3 月 8 日
編集済み: Sven 2014 年 3 月 8 日
Hi Edgar,
You can set the XTick locations of an axis (or the current one via gca) directly:
tickValues = min(x):0.1:max(x);
set(gca,'XTick',tickValues)
Notice that I chose tick spacing of 0.1 and it is already a very very tight grid. Your request of having grid spacing of 0.001 is actually not very reasonable for this data as it would result in 6000 grid lines between 0 and 6. Your screen resolution is much lower than that so you're basically requesting 6 lines per pixel (ie, not possible).
You can also turn the XMinorGrid on, and it will put a lighter grid between your specified major tick locations. Note that you don't have 100% control over what lines will be shown on this grid. MATLAB chooses a "reasonable" number of lines between each tick to match the displayed size of the figure - usually 1, 2, or 5.
set(gca,'XTick',0:1:6, 'XMinorTick','on')
Hope this helped answer your question.

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by