MATLAB - 绘制多个图形

发布于 2024-12-06 08:00:16 字数 1042 浏览 0 评论 0原文

我是 MATLAB 新手,在绘制多个图形时遇到困难。以下是我要绘制的向量:

S = [1.2421
     2.3348
     0.1326
     2.3470
     6.7389
     3.7089
     11.8534
     -1.8708
     ...]

Y = [1.1718
     1.8824
     0.3428
     2.1057
     1.6477
     2.3624
     2.1212
    -0.7971
    ...]

w = [0.1753
     0.3277]

S 是我的训练数据,Y 是我的输出向量。然后,我向训练数据添加一个列向量:

O = ones(length(S), 1)
X = [S 0]

w = inv(X'*X)*X'*Y

因此,我尝试在同一个图表上绘制 XYw。我首先绘制 w,然后按住 X,这就是我迷路的地方。基本上它们不在同一尺度上,因为 x 的大小远小于 XXY 都是大小为 100 的向量, w 的大小为 2)。

plot(w)

在 MATLAB 中:plot(w) 的结果

然后我这样做:

hold
plot(X)

在 MATLAB 中:保持结果,plot(X)

现在我绘制的 wX 的图相比是如此之小>。我怎样才能使它们具有相同的比例?也可能让它们有不同的颜色?

I am new to MATLAB and am having difficulty plotting multiple graphs. Here are my vectors to graph:

S = [1.2421
     2.3348
     0.1326
     2.3470
     6.7389
     3.7089
     11.8534
     -1.8708
     ...]

Y = [1.1718
     1.8824
     0.3428
     2.1057
     1.6477
     2.3624
     2.1212
    -0.7971
    ...]

w = [0.1753
     0.3277]

S is my training data and Y is my output vector. Then I add a column vector to my training data:

O = ones(length(S), 1)
X = [S 0]

w = inv(X'*X)*X'*Y

So I am trying to plot X, Y and w on the same graph. I plot w first, hold, X and this is where I get lost. Basically they are not on the same scale because the size of x is much less than X (X and Y are both vectors of size 100 and w is of size 2).

plot(w)

In MATLAB: result of plot(w)

Then I do:

hold
plot(X)

In MATLAB: result of hold, plot(X)

Now the w that I plotted is so small compared to the plot of X. How would I make them the same scale? Also maybe making them a different color?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

淤浪 2024-12-13 08:00:16

plotyy 将创建您正在寻找的图形。请参阅链接中的示例以进行进一步的绘图自定义。

plotyy will create the figure you are looking for. See the examples in the link for further plot customization.

2024-12-13 08:00:16

我只是发表评论,但我没有足够的声誉......如果您的目的不是呈现数据,而只是能够将其可视化,您可以重新调整数据集并避免不太容易的情况-work-with plotyy (尽管它最好的答案):

W = W/max(W);
X = X/max(X);
plot(W)
hold on
plot(X)

有关绘图的其他格式,请参阅 mathworks polt。在那里你可以改变颜色、线宽等等。

I'd just comment, but I don't have enough reputation... If you are not aiming to present the data, but just be able to visualize it, you can rescale your datasets and avoid the not-so-easy-to-work-with plotyy (although it is the best answer):

W = W/max(W);
X = X/max(X);
plot(W)
hold on
plot(X)

For additional formating of the plots, see mathworks polt. There you can change color, linewidth and whatnot.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文