[英]How to plot input and output data in MATLAB
I have a 2 Dimensional input data; 我有一个二维输入数据; a set of vector with 2 components, let's say 200. And for each one of those I have a scalar value given to them.
一组具有2个成分的向量,比方说200。对于每个成分,我都有一个标量值。
So it's basically something like this: 所以基本上是这样的:
{ [input1(i) input2(i)] , output(i) } where i goes from 1 to 200
I would like to make a 3 Dimensional plot with this data, but I don't know how exactly. 我想使用此数据绘制3维图,但我不知道它的精确度。 I have tried with
surf
. 我尝试过
surf
。 I have done a meshgrid
with the input value, but I don't know how to obtain a matrix out of the output data in order to do a surf
. 我已经用输入值完成了
meshgrid
,但是我不知道如何从输出数据中获取矩阵来进行surf
。
How can I get a 3 Dimensional plot with this data? 如何使用此数据获得三维图?
Assuming your input data is 'randomly' spaced: 假设您的输入数据是“随机”隔开的:
>> inputs = randn(400, 2);
>> outputs = inputs(:, 1) .* inputs(:, 2); % some function for the output
You could simply plot a scatter3 plot of these data: 您可以简单地绘制这些数据的散点图 :
>> scatter3(inputs(:, 1), inputs(:, 2), outputs)
But a better way is to interpolate, using TriScatteredInterp so you can plot the underlying function as a surface: 但是更好的方法是使用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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.