是否有可能组装几个选项并传递给matlab中的plot函数(Is that possible to assemble several options and pass to the plot func

编程入门 行业动态 更新时间:2024-10-19 22:41:50
是否有可能组装几个选项并传递给matlab中的plot函数(Is that possible to assemble several options and pass to the plot function in matlab)

我正在使用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.

更多推荐

本文发布于:2023-07-22 09:57:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219152.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:几个   有可能   函数   选项   matlab

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!