如何在Matlab中绘制图?

时间:2016-04-06 17:02:16

标签: matlab plot sampling

MATLAB中的图如下所示:

enter image description here

生成此代码的代码非常简单:

 y = [0 18 450];
 x = [0 5.3 6.575];
 plot(x,y);

我怎么知道这个图上119个等间距离散点的值?

1 个答案:

答案 0 :(得分:3)

在简单的MATLAB图中,点通过简单的线性插值连接在一起。简单地说,在每对点之间绘制一条直线。除了用于绘制点数的点之外,您无法从图形中获取这些点(至少不容易......)。

如果您确实需要等间隔的119个点,理论上从上面的4个点中获得,您可以使用interp1函数来执行此操作:

y = [0 18 450];
x = [0 5.3 6.575]
yy = interp1(x, y, linspace(min(x),max(x),119), 'linear');

interp1执行线性(请注意最后的'linear'标志...)插值给定由xy点和一组定义的一组关键点x点的x点用于在关键y点之间进行插值,以生成yy中存储的插值x点。在这种情况下,linspace会生成一个线性增加的数组,从x中的最小值到>> format compact; >> y = [0 18 450]; >> x = [0 5.3 6.575]; >> yy = interp1(x, y, linspace(min(x),max(x),119), 'linear'); >> yy yy = Columns 1 through 8 0 0.1892 0.3785 0.5677 0.7570 0.9462 1.1354 1.3247 Columns 9 through 16 1.5139 1.7031 1.8924 2.0816 2.2709 2.4601 2.6493 2.8386 Columns 17 through 24 3.0278 3.2171 3.4063 3.5955 3.7848 3.9740 4.1633 4.3525 Columns 25 through 32 4.5417 4.7310 4.9202 5.1094 5.2987 5.4879 5.6772 5.8664 Columns 33 through 40 6.0556 6.2449 6.4341 6.6234 6.8126 7.0018 7.1911 7.3803 Columns 41 through 48 7.5696 7.7588 7.9480 8.1373 8.3265 8.5157 8.7050 8.8942 Columns 49 through 56 9.0835 9.2727 9.4619 9.6512 9.8404 10.0297 10.2189 10.4081 Columns 57 through 64 10.5974 10.7866 10.9759 11.1651 11.3543 11.5436 11.7328 11.9220 Columns 65 through 72 12.1113 12.3005 12.4898 12.6790 12.8682 13.0575 13.2467 13.4360 Columns 73 through 80 13.6252 13.8144 14.0037 14.1929 14.3822 14.5714 14.7606 14.9499 Columns 81 through 88 15.1391 15.3283 15.5176 15.7068 15.8961 16.0853 16.2745 16.4638 Columns 89 through 96 16.6530 16.8423 17.0315 17.2207 17.4100 17.5992 17.7885 17.9777 Columns 97 through 104 34.6540 53.5334 72.4128 91.2921 110.1715 129.0508 147.9302 166.8096 Columns 105 through 112 185.6889 204.5683 223.4477 242.3270 261.2064 280.0857 298.9651 317.8445 Columns 113 through 119 336.7238 355.6032 374.4826 393.3619 412.2413 431.1206 450.0000 中的最大值,其中包含119个这些点。

以下是您的数据的运行示例:

Message: Failed to complete #destroy action: [Expected process to exit with [0], but received '1'
---- Begin output of vagrant destroy -f ----
STDOUT: ==> default: Forcing shutdown of VM...
STDERR: There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["controlvm", "3fa0e654-df44-4050-809f-2d1474b74a8f", "poweroff"]
Stderr: 0%...10%...20%...30%...40%...50%...
Progress state: NS_ERROR_FAILURE
VBoxManage: error: Failed to power off machine
VBoxManage: error: The VM session was aborted
VBoxManage: error: Details: code NS_ERROR_FAILURE (0x80004005), component SessionMachine, interface ISession
VBoxManage: error: Context: "RTEXITCODE handleControlVM(HandlerArg*)" at line 234 of file VBoxManageControlVM.cpp
---- End output of vagrant destroy -f ----
Ran vagrant destroy -f returned 1]