I am using MATLAB to plot several figures and hope these figure use the same plot options, it looks something like this:
N = 20;
Fs = 200;
t = (0:N-1)/Fs;
x = sin(2*pi*10*t);
y = cos(2*pi*20*t);
z = x + y;
figure(1),clf;
subplot(311);
plot(t, x, 'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3);
grid on;
subplot(312);
plot(t, y, 'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3);
grid on;
subplot(313);
plot(t, z, 'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3);
grid on;
You can see the plot options are exactly the same. If I want to change the style, I have to change each of them. Is that possible assemble/group them together and pass them to the plot function?
I have tried to put them in a cell like this plotOptions = {'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3}; It doesn't work. The reason might be the plot functions would take the plotOptions as one paramter and thus failed to parse it.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With