问题描述
我正在使用matlab绘制多个图形,并希望这些图形使用相同的图形选项.更具体地说,它看起来像这样.
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 = 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?
我试图将它们放在这样的单元格中plotOptions = {'bs-','MarkerFaceColor','b','LineWidth',3};它不起作用. 原因可能是plot函数会将plotOptions作为一个参数,因此无法解析.
I have tried to put them in a cell like thisplotOptions = {'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.
这篇关于是否可以组装几个选项并传递给Matlab中的plot函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!