Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MATLAB-在一个图形中绘制多个曲面拟合_Matlab_Plot_Colors_3d_Surface - Fatal编程技术网

MATLAB-在一个图形中绘制多个曲面拟合

MATLAB-在一个图形中绘制多个曲面拟合,matlab,plot,colors,3d,surface,Matlab,Plot,Colors,3d,Surface,我有3套3D坐标,每一套都安装了飞机。现在,我想在一个图中绘制所有数据点和3个平面 到目前为止,我有以下功能: function [fitresult, gof] = create_fit(xx, yy, zz, grp) [xData, yData, zData] = prepareSurfaceData( xx, yy, zz ); ft = fittype( 'poly11' ); opts = fitoptions( ft ); opts.Lower = [-Inf -Inf -In

我有3套3D坐标,每一套都安装了飞机。现在,我想在一个图中绘制所有数据点和3个平面

到目前为止,我有以下功能:

function [fitresult, gof] = create_fit(xx, yy, zz, grp)

[xData, yData, zData] = prepareSurfaceData( xx, yy, zz );

ft = fittype( 'poly11' );
opts = fitoptions( ft );
opts.Lower = [-Inf -Inf -Inf];
opts.Upper = [Inf Inf Inf];

hold on;
% figure( 'Name', 'fit1' );
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );
h = plot( fitresult, [xData, yData], zData);
if grp == 1
    colormap(hot);
elseif grp == 2
    colormap(cool);
else
    colormap(grey);
end

legend( h, 'fit1', 'zz vs. xx, yy', 'Location', 'NorthEast' );

xlabel( 'xx' );
ylabel( 'yy' );
zlabel( 'zz' );
grid on
function [fitresult, gof, h] = create_fit(xx, yy, zz, color)

[xData, yData, zData] = prepareSurfaceData( xx, yy, zz );

ft = fittype( 'poly11' );
opts = fitoptions( ft );
opts.Lower = [-Inf -Inf -Inf];
opts.Upper = [Inf Inf Inf];

hold on;
[fitresult, gof] = fit( [xData, yData], zData, ft, opts );

h = plot( fitresult, [xData, yData], zData);

set(h(1), 'FaceColor', color);
set(h(2), 'MarkerFaceColor', color, 'MarkerEdgeColor', 'k');
% Define sample data
N = 20;
x = rand(1,N);
y = rand(1,N);
z = rand(1,N);

% Call the function, specify color
[f1, gof1, h1] = create_fit(x, y, z, 'r');
[f2, gof2, h2] = create_fit(x, y.^10, z, 'g');
[f3, gof3, h3] = create_fit(x.^10, y, z, 'b');

% Figure adjustments
xlabel( 'xx' );
ylabel( 'yy' );
zlabel( 'zz' );
view(3)
grid on

xlim([min(x) max(x)]);
ylim([min(y) max(y)]);
zlim([min(z) max(z)]);
但是,这有两个问题:

  • 单独打印时,平面将根据也使用它们打印的数据点进行缩放。当平面绘制在一起时,它们的比例很差,数据点会收敛到一个小水滴(与平面相比,比例非常小) 我尝试用
    轴([-0.04 0.04-0.04 0.04-0.04-0.04 0.04-1 1])修复问题,但它是硬编码的,看起来还是有点不对劲。
    

  • colormap
    命令似乎只有在第一次调用时才起作用。因此,所有的飞机都是蓝色的。如何对每个平面和适合该平面的点进行不同的着色

  • 这是绘制多个平面的最佳方法吗

  • 编辑

    这是我最初答案的编辑版本。
    plot
    的输出是一个两元素图形对象,因此您必须分别调用
    h(1)
    h(2)
    来设置平面和数据点的属性

    以下是该函数的代码:

    function [fitresult, gof] = create_fit(xx, yy, zz, grp)
    
    [xData, yData, zData] = prepareSurfaceData( xx, yy, zz );
    
    ft = fittype( 'poly11' );
    opts = fitoptions( ft );
    opts.Lower = [-Inf -Inf -Inf];
    opts.Upper = [Inf Inf Inf];
    
    hold on;
    % figure( 'Name', 'fit1' );
    [fitresult, gof] = fit( [xData, yData], zData, ft, opts );
    h = plot( fitresult, [xData, yData], zData);
    if grp == 1
        colormap(hot);
    elseif grp == 2
        colormap(cool);
    else
        colormap(grey);
    end
    
    legend( h, 'fit1', 'zz vs. xx, yy', 'Location', 'NorthEast' );
    
    xlabel( 'xx' );
    ylabel( 'yy' );
    zlabel( 'zz' );
    grid on
    
    function [fitresult, gof, h] = create_fit(xx, yy, zz, color)
    
    [xData, yData, zData] = prepareSurfaceData( xx, yy, zz );
    
    ft = fittype( 'poly11' );
    opts = fitoptions( ft );
    opts.Lower = [-Inf -Inf -Inf];
    opts.Upper = [Inf Inf Inf];
    
    hold on;
    [fitresult, gof] = fit( [xData, yData], zData, ft, opts );
    
    h = plot( fitresult, [xData, yData], zData);
    
    set(h(1), 'FaceColor', color);
    set(h(2), 'MarkerFaceColor', color, 'MarkerEdgeColor', 'k');
    
    % Define sample data
    N = 20;
    x = rand(1,N);
    y = rand(1,N);
    z = rand(1,N);
    
    % Call the function, specify color
    [f1, gof1, h1] = create_fit(x, y, z, 'r');
    [f2, gof2, h2] = create_fit(x, y.^10, z, 'g');
    [f3, gof3, h3] = create_fit(x.^10, y, z, 'b');
    
    % Figure adjustments
    xlabel( 'xx' );
    ylabel( 'yy' );
    zlabel( 'zz' );
    view(3)
    grid on
    
    xlim([min(x) max(x)]);
    ylim([min(y) max(y)]);
    zlim([min(z) max(z)]);
    
    下面是调用函数的示例脚本:

    function [fitresult, gof] = create_fit(xx, yy, zz, grp)
    
    [xData, yData, zData] = prepareSurfaceData( xx, yy, zz );
    
    ft = fittype( 'poly11' );
    opts = fitoptions( ft );
    opts.Lower = [-Inf -Inf -Inf];
    opts.Upper = [Inf Inf Inf];
    
    hold on;
    % figure( 'Name', 'fit1' );
    [fitresult, gof] = fit( [xData, yData], zData, ft, opts );
    h = plot( fitresult, [xData, yData], zData);
    if grp == 1
        colormap(hot);
    elseif grp == 2
        colormap(cool);
    else
        colormap(grey);
    end
    
    legend( h, 'fit1', 'zz vs. xx, yy', 'Location', 'NorthEast' );
    
    xlabel( 'xx' );
    ylabel( 'yy' );
    zlabel( 'zz' );
    grid on
    
    function [fitresult, gof, h] = create_fit(xx, yy, zz, color)
    
    [xData, yData, zData] = prepareSurfaceData( xx, yy, zz );
    
    ft = fittype( 'poly11' );
    opts = fitoptions( ft );
    opts.Lower = [-Inf -Inf -Inf];
    opts.Upper = [Inf Inf Inf];
    
    hold on;
    [fitresult, gof] = fit( [xData, yData], zData, ft, opts );
    
    h = plot( fitresult, [xData, yData], zData);
    
    set(h(1), 'FaceColor', color);
    set(h(2), 'MarkerFaceColor', color, 'MarkerEdgeColor', 'k');
    
    % Define sample data
    N = 20;
    x = rand(1,N);
    y = rand(1,N);
    z = rand(1,N);
    
    % Call the function, specify color
    [f1, gof1, h1] = create_fit(x, y, z, 'r');
    [f2, gof2, h2] = create_fit(x, y.^10, z, 'g');
    [f3, gof3, h3] = create_fit(x.^10, y, z, 'b');
    
    % Figure adjustments
    xlabel( 'xx' );
    ylabel( 'yy' );
    zlabel( 'zz' );
    view(3)
    grid on
    
    xlim([min(x) max(x)]);
    ylim([min(y) max(y)]);
    zlim([min(z) max(z)]);
    
    结果是:


    最小-最大技巧奏效了。但是,“FaceColor”出现以下错误:
    参数“FaceColor”与解析器的任何有效参数都不匹配。
    另外,是否有一种方法可以使每组点具有不同的颜色?这将有助于可视化拟合的效果,并发现异常值。好的,抱歉,但由于我们没有您拥有的所有信息(值
    xx
    grp
    ,…),我无法真正测试我的答案。用
    'color'
    替换
    'Facecolor'
    怎么样?
    xx、yy、zz
    只是相同长度的1D双倍数组
    grp
    可以是1、2或3,具体取决于平面。尝试“color”或“color”会出现相同的错误:/