Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Matlab 如何在yyaxis子批次中链接两个y轴?_Matlab_Matlab Figure_Subplot - Fatal编程技术网

Matlab 如何在yyaxis子批次中链接两个y轴?

Matlab 如何在yyaxis子批次中链接两个y轴?,matlab,matlab-figure,subplot,Matlab,Matlab Figure,Subplot,我试图在yyaxis子批次中分别链接两个y轴。到目前为止,我只通过调用linkaxes(g)链接给定代码中的右y轴,其中g是轴句柄。如何使左y轴彼此链接 谢谢 g(1) = subplot(2,1,1); hold on; yyaxis left; plot(rand(10,1)); yyaxis right; plot(2*rand(10,1)); hold off; g(2) = subplot(2,1,2); hold on; yyaxis left; plot(2*rand(10,1)

我试图在yyaxis子批次中分别链接两个y轴。到目前为止,我只通过调用
linkaxes(g)
链接给定代码中的右y轴,其中
g
是轴句柄。如何使左y轴彼此链接

谢谢

g(1) = subplot(2,1,1);
hold on;
yyaxis left;
plot(rand(10,1));
yyaxis right;
plot(2*rand(10,1));
hold off;

g(2) = subplot(2,1,2);
hold on;
yyaxis left;
plot(2*rand(10,1));
yyaxis right;
linkaxes(g);
plot(rand(10,1));
hold off;

一个
对象具有只读属性
YAxisLocation
,该属性在每次调用
yyaxis
时设置,并记住上次使用的轴。当您键入
linkaxes(g)
时,它只取右轴,因为这是您设置的最后一个轴。要查看是否可以为第一个轴运行此代码:

g(1) = subplot(2,1,1);
hold on;
yyaxis right;
plot(2*rand(10,1));
yyaxis left;
plot(rand(10,1));
hold off;
并查看这一次左上轴是如何链接到右下轴的

如果要链接两个轴,只需在代码末尾添加以下行,以再次引用左轴:

yyaxis(g(1),'left')
yyaxis(g(2),'left')
linkaxes(g);
或者,您可以抓住数字标尺的手柄,使用
linkprop
(无需调用
linkaxes
):

您应该在创建所有轴后添加此项,以便已指定所有控制柄

Y = get(g,'YAxis');
Y = [Y{:}];
linkprop(Y(1,:),'Limits')
linkprop(Y(2,:),'Limits')