I am new to MATLAB. When I use plot command, it displays the graph but by default grid is OFF. I have to use grid on command, each & every time I use the plot command. Is there a way that will turn grid on with the plot command?

 Akzeptierte Antwort

Stephen23
Stephen23 am 9 Mai 2015
Bearbeitet: Stephen23 am 9 Mai 2015

4 Stimmen

Welcome to MATLAB!
Setting the some default parameters can be achieved by following these steps:
  1. Look up the axes properties and locate the ones that are of interest to you.
  2. use set to define the settings that you want, according to these instructions.
So, just to get you started, here is what I just tried after a fresh restart:
>> set(0,'DefaultAxesXGrid','on')
>> plot([0,1,2],[2,3,2])
which produced this:
Note that recent versions use groot (from 2014?), older versions simply used 0 to indicate the graphics root.
If you want these setting to be the default every time you start MATLAB< then you can put theses commands in a startup Mfile.

2 Kommentare

Elia D'Orazio
Elia D'Orazio am 8 Mai 2020
It works but after i close and then open again matlab the grid default property comes back to off. How to make it permanent?
I don't remember exactly how but the there is a "run these files on startup thing" in matlab

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Arvind Srivastav
Arvind Srivastav am 31 Okt. 2019

0 Stimmen

Why does it show only verticle lines?

1 Kommentar

Steven Lord
Steven Lord am 31 Okt. 2019
Because Stephen only changed the default value for the axes object's XGrid property.
Setting DefaultAxesXGrid changes the
Default value of
(future) Axes objects'
XGrid property
There are corresponding YGrid and ZGrid properties.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Graphics Object Properties finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by