我正在使用matlab来绘制几个数字,并希望这些数字使用相同的绘图选项。 更具体地说,它看起来像这样。
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;你可以看到情节选项完全一样。 如果我想改变风格,我必须改变它们中的每一个。 这是可能的组合/分组在一起,并将它们传递给剧情功能?
我试图把它们放在像这样的单元格中。plotOptions = {'bs-','MarkerFaceColor','b','LineWidth',3}; 它不起作用。 原因可能是情节函数会将plotOptions作为一个参数,从而无法解析它 。
有没有人有解决方案?
亲切的问候。
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?
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.
Is there any one have a solution?
Kind regards.
最满意答案
使用具有选项的单元格已经是一种好方法。 只需使用{:} ,如下所示:
opt = {'bs-', 'MarkerFaceColor', 'b', 'LineWidth', 3}; figure(1),clf; subplot(311); plot(t, x, opt{:});然后,单元格的每个元素被评估为单个参数。
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.
更多推荐
发布评论