If I run the following code (within a script or command window) several times, then the minor grids will be 'on' only every other time. Why?
x=-2*pi:0.1:2*pi;
y=sin(x);
figure(1)
hold on
plot(x,y);
grid on
grid minor

 採用された回答

Walter Roberson
Walter Roberson 2021 年 4 月 9 日

0 投票

grid minor toggles the visibility of the minor grid lines. Minor grid lines lie between the tick marks. Not all types of charts support minor grid lines.
You probably want
set(gca, 'XMinorGrid', 'on', 'YMinorGrid', 'on')

3 件のコメント

G A
G A 2021 年 4 月 10 日
編集済み: G A 2021 年 4 月 10 日
Thanks, Walter! With that line you have given instead of grid minor my code works now properly for each run. However, still, why with the run number 1,3,5... the code with grid minor gives proper result and with the run number 2,4,6,... it gives a wrong result?
Walter Roberson
Walter Roberson 2021 年 4 月 10 日
grid minor toggles the visibility of the minor grid lines
So the first time you call it, it turned it from default off to on. The second time you call it, it turns it off. The third time you call it, it turns it on...
G A
G A 2021 年 4 月 10 日
Understood. Thanks!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeApp Building についてさらに検索

製品

リリース

R2020b

タグ

質問済み:

G A
2021 年 4 月 9 日

コメント済み:

G A
2021 年 4 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by