ax.gridcolor = [0 0 1]; in matlab

To set the color of grids in MATLAB, you can use the GridColor property of either the Axes object or the Line object. Here is an example of how to set the grid color of an Axes object:

main.m
% create a simple plot
x = linspace(0, 2*pi, 100);
y = sin(x);
plot(x, y);

% get the axes object
ax = gca;

% set the grid color
ax.GridColor = [0 0 1];  % blue
162 chars
11 lines

In this example, gca is used to get the current Axes object, which is stored in a variable named ax. Then, the GridColor property of ax is set to [0 0 1], which is the RGB value for blue.

Alternatively, you can set the grid color of a specific Line object in a plot like this:

main.m
% create a simple plot with two lines
x = linspace(0, 2*pi, 100);
y1 = sin(x);
y2 = cos(x);
plot(x, y1, x, y2);

% get the first line object
lines = findobj(gcf, 'Type', 'Line');
line1 = lines(1);

% set the grid color of line1
line1.Color = 'b';
line1.LineStyle = '--';
line1.LineWidth = 2;
line1.Marker = 'o';
line1.MarkerFaceColor = 'b';
341 chars
17 lines

In this example, findobj is used to get a list of all the Line objects in the current figure. Then, the first Line object is stored in a variable named line1. Finally, line1's color, LineStyle, LineWidth, Marker, and MarkerFaceColor are all set to different values.

related categories

gistlibby LogSnag