MATLAB cftool表面图矩阵 [英] MATLAB cftool surface plot matrix
问题描述
我有一组不规则的数据点,这些数据点的形式为笛卡尔坐标,使用MATLAB cftool可以将其转换为一个曲面(见下文).
I have a irregular set of data points in the form of cartesian coordinates which using the MATLAB cftool can be turned into a surface (see below).
有人知道一种访问MATLAB生成的笛卡尔坐标矩阵以绘制该表面的方法吗?
Does anyone know a way to access the matrix of cartesian coordinates that MATLAB generates in order for it to plot this surface?
为该图形生成的代码(如下所示)无法访问必须产生以适合曲面的任何其他插值点.
The code generated for this graph (seen below) provides no access to the any additional interpolated points which must be produced to fit the surface.
%% Fit: 'untitled fit 1'.
[xData, yData, zData] = prepareSurfaceData( x1, y1, z1 );
% Set up fittype and options.
ft = 'linearinterp';
% Fit model to data.
[fitresult, gof] = fit( [xData, yData], zData, ft, 'Normalize', 'on' );
% Plot fit with data.
figure( 'Name', 'untitled fit 1' );
h = plot( fitresult, [xData, yData], zData );
legend( h, 'untitled fit 1', 'z1 vs. x1, y1', 'Location', 'NorthEast' );
% Label axes
xlabel x1
ylabel y1
zlabel z1
grid on
预先感谢
推荐答案
作为一种可能的解决方法(可能效率不高)是绘制拟合结果(fitresult
)并获取XData
,YData
和绘制表面的ZData
属性.
As a possible workaround (potentially not very efficient) is to plot the output of the fit (fitresult
) and fetch the XData
, YData
and ZData
properties of the plotted surface.
例如,在执行虚拟拟合之后:
For example, after performing a dummy fit:
hP = plot(fitresult)
产生hP
的那些属性:
Surface (curvefit.gui.FunctionSurface) with properties:
EdgeColor: [0 0 0]
LineStyle: '-'
FaceColor: 'flat'
FaceLighting: 'flat'
FaceAlpha: 1
XData: [51x49 double]
YData: [51x49 double]
ZData: [51x49 double]
CData: [51x49 double]
因此您可以检索它们.
So you can retrieve them.
替代
或者,您可以使用cftool
生成的代码为函数提供其他输出参数(称为createFit
或类似的东西).因此,当您使用足够的参数调用该函数时,您将直接获得这些坐标.
as an alternative, you could use the code generated by cftool
to provide additional output arguments to the function (called createFit
or somethinbg like this). Therefore, as you call the function with enough arguments you will obtain those coordinates directly.
示例:
更改生成的函数的标头,如下所示:
change the header of the generated function like so:
[fitresult, gof,a,b,c] = createFit1(x, y, z)
,然后在函数正文中:
a = xData;
b = yData;
c = zData;
然后在命令窗口中调用该函数,例如,在a
,b
和c
中产生正确的坐标.
then calling the function in the Command Window, for example, yields the right coordinates in a
,b
and c
.
这篇关于MATLAB cftool表面图矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!