grid on in matlab

To display a grid on a figure in MATLAB, you can use the grid command. Here's an example:

main.m
% Define x and y data
x = linspace(0, 2*pi);
y = sin(x);

% Plot data
plot(x, y)

% Turn on the grid
grid on
109 chars
10 lines

In this example, we first define some x and y data (in this case, we're plotting a sine wave). We then use the plot command to create a figure and display the data. Finally, we use the grid on command to turn on the grid.

You can also customize the appearance of the grid using additional arguments to the grid command. For example:

main.m
% Define x and y data
x = linspace(0, 2*pi);
y = sin(x);

% Plot data
plot(x, y)

% Customize grid appearance
grid on
grid minor
set(gca, 'GridLineStyle', '--')
161 chars
12 lines

In this example, we first define the same x and y data as before. We then plot the data and turn on the grid using grid on. Next, we use grid minor to add a second, fainter grid. Finally, we use set to customize the appearance of the grid lines (in this case, we're setting the line style to "--").

related categories

gistlibby LogSnag