绘制两个轴半对数 matlab

plotting two axes semilog matlab

我有 2 个具有相同 x 数据的地块:

x=[0 100];
y1=x^2;
y2=e^x;

我想用 semilogy(即对数刻度)绘制 y2。 我怎样才能将它们一起绘制? 左侧——y1 Y轴; 右侧-y2 Y轴;

嗯,快速 Google 搜索您在问题中提供的术语(即 'semilogy''plotting two axes matlab') 会告诉你我给你看的东西。无论如何...

您可以使用内置的 yyaxis function 来...

Create a chart with two y-axes.

您可以使用内置的 semilogy function 来...

Create a plot with a logarithmic scale for the y-axis and a linear scale for the x-axis.

将它们放在一起,这几乎只是我在上面链接的 yyaxis 函数文档中提供的代码的通用版本...

x = [ insert your x-data];
y1 = insert-your-first-func;
yyaxis left
plot(x,y1)

y2 = insert-your-second-func;
yyaxis right
semilogy(x,y2)

编辑: 如果使用 Matlab 版本 <2016a,那么您将无法利用 yyaxis 函数的实用程序。在这种情况下,Whosebug 上有很多问题(例如 this one and that one),这些问题解释了如何在相同的 x 轴但不同的 y 轴(即线性和半对数,例如)。

答案也在plotyy documentation中呢!这是:

plotyy(X1,Y1,X2,Y2,'function1','function2') uses function1(X1,Y1) to plot the data for the left axis and function2(X2,Y2) to plot the data for the right axis.

function can be either a function handle or a string specifying plot, semilogx, semilogy, loglog, stem, or any MATLAB® function that accepts the syntax: h = function(x,y)

上面的代码现在看起来像...

x = [ insert your x-data];
y1 = insert-your-first-func;
y2 = insert-your-second-func;
plotyy(x,y1,x,y2,'plot','semilogy');

编码愉快!记住 Google 是你的朋友!