Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档
资料存档 资料存档
回复
 
主题工具 显示模式
旧 2019-12-10, 20:48   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
帖子 如何在MATLAB中绘制输入和输出数据

我有一个二维输入数据;一组具有2个成分的向量,比方说200。对于每个成分,我都有一个标量值。

所以基本上是这样的:

{ [input1(i) input2(i)] , output(i) } where i goes from 1 to 200 我想使用此数据绘制3维图,但我不知道它的精确度。我尝试过surf 。我已经用输入值完成了meshgrid ,但是我不知道如何从输出数据中获取矩阵来进行surf 。

如何使用此数据获得三维图?



回答:

假设您的输入数据是“随机”隔开的:

>> inputs = randn(400, 2); >> outputs = inputs(:, 1) .* inputs(:, 2); % some function for the output 您可以简单地绘制这些数据的散点图

>> scatter3(inputs(:, 1), inputs(:, 2), outputs)

但是更好的方法是使用TriScatteredInterp进行插值,以便可以将基础函数绘制为曲面:

% create suitably spaced mesh... gridsteps_x = min(inputs(:, 1)):0.5:max(inputs(:, 1)); gridsteps_y = min(inputs(:, 2)):0.5:max(inputs(:, 2)); [X, Y] = meshgrid(gridsteps_x, gridsteps_y); % Compute function to perform interpolation: F = TriScatteredInterp(inputs(:, 1), inputs(:, 2), outputs); % Calculate Z values using function F: Z = F(X, Y); % Now plot this, with original data: mesh(X, Y, Z); hold on scatter3(inputs(:, 1), inputs(:, 2), outputs); hold off



更多&回答...
poster 当前离线   回复时引用此帖
回复


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛禁用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 23:51


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.