I am using matlab to plot several figures and hope these figure use the same plot options. To be more specific, it looks something like this.
N = 20;
Fs = 20
A very clean alternative approach would be to keep the plot command as simple as possible and manipulate the handles afterwards.
opts = {'Color','red','MarkerFaceColor', 'b', 'LineWidth',3};
h(1) = plot(t, x);
grid on;
subplot(312);
h(2) = plot(t, y);
grid on;
subplot(313);
h(3) = plot(t, z);
grid on;
arrayfun(@(x) set(x,opts{:}),h)
The advantage over the indeed neat approach by Nemesis is, that in case you have multiple sets of properties, like:
opts.slimRed = {'Color','red','MarkerFaceColor', 'b', 'LineWidth',1};
opts.fatBlue = {'Color','blue','MarkerFaceColor', 'b', 'LineWidth',5};
and you want to exchange them, you just need to modify one variable
arrayfun(@(x) set(x,opts.fatBlue{:}),h)
to change the appearance of a whole set of handles h
.
Solution with unique plotting function:
subplot(312);
myplot(t,y)
Save myplot
function as a separate m-file.
function myplot(t,x)
plot(t, x, 'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3);
end
The cell answer is good, another option is to set the arg value to be a variable:
faceColor = 'b';
lineWidth = 3;
figure(1),clf;
subplot(311);
plot(t, x, 'bs-', 'MarkerFaceColor', faceColor, 'LineWidth', lineWidth);
subplot(312);
plot(t, y, 'bs-', 'MarkerFaceColor', faceColor, 'LineWidth', lineWidth);
subplot(313);
plot(t, z, 'bs-', 'MarkerFaceColor', faceColor, 'LineWidth', lineWidth);
Using a cell with the options was already a good approach. Just use {:}
, as below:
opt = {'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3};
figure(1),clf;
subplot(311);
plot(t, x, opt{:});
Then, each element of the cell is evaluated as single argument.