使用MATLAB点表示法一次设置多个属性

使用MATLAB点表示法一次设置多个属性,matlab,plot,Matlab,Plot,最近,MATLAB启用了绘图句柄,以使用点符号设置属性 e、 g 现在可以 plotLeft(1).Marker = 'o'; 可以使用这种新的点表示法一次设置多个字段吗。下面是一些代码示例: clc; clear all; x = logspace(-3,0,100)'; plot1 = sin(x); plot2 = cos(x); [hax,plotLeft,plotRight] = plotyy(x,[plot1 plot1],x,[plot2 plot2]) plotLeft(1).

最近,MATLAB启用了绘图句柄,以使用点符号设置属性

e、 g

现在可以

plotLeft(1).Marker = 'o';
可以使用这种新的点表示法一次设置多个字段吗。下面是一些代码示例:

clc; clear all;
x = logspace(-3,0,100)';
plot1 = sin(x);
plot2 = cos(x);
[hax,plotLeft,plotRight] = plotyy(x,[plot1 plot1],x,[plot2 plot2])
plotLeft(1).Marker = 'o';
plotLeft(2).Marker = 'x';
我想设置这一位:

plotLeft(1).Marker = 'o';
plotLeft(2).Marker = 'x';
但是在一行。我可以通过以下方式访问标记类型:

plotLeft([1 2]).Marker
但这不会让我告诉他们我认为它会如何运作:

>> plotLeft([1 2]).Marker = ['o' 'x']
Insufficient number of outputs from function on right hand side of equal sign to
satisfy overloaded assignment.

您可以使用函数来实现这一点:

[plotLeft([1 2]).Marker] = deal('o', 'x');
plotLeft([1 2])。标记创建一个标记,因此您不能直接分配给它,但您可以使用deal来处理它,它将等效于:

[plotLeft(1).Marker, plotLeft(2).Marker] = deal('o', 'x');

谢谢,我从没听说过这笔交易。我只希望有一种像我写的那样更快的方法,因为这种方法有点脱离了点符号的有用性,回到了我们“设置”事物的方式。因为在这种情况下
plotLeft
只包含两个元素,你也可以使用更简单的
[plotLeft.Marker]=deal('o','x')
。不需要
([1,2])
索引。如果要多次分配相同的标记类型,另一种可能有用的语法是
m={'o','x'};[plotLeft.Marker]=m{:}
[plotLeft(1).Marker, plotLeft(2).Marker] = deal('o', 'x');