matlab 3维散点图surf化

在很多时候我们需要将matlab或其他数据得到的3D散点图,变成一个曲面。这里我们介绍如何使用matlab实现surface。

clear all
clc
close all

% generate the data in domain [-1,1] 
N2point2 = 500;
X = -1.0+2*rand(1, N2point2);
Y = -1.0+2*rand(1, N2point2);
u = sin(X.^2+Y.^2);

% construct the scatter solution by point pairs
figure('name','udot')
plot3(X,Y, u,'.');
hold on

 

% Meshing the scatter solution 
% The key pointis that getting the mesh by X and  Y.  Firstly, unique X and Y
Xcoord = unique(X);
Ycoord = unique(Y);

% secondly, obtain the mesh by Xcoord and Ycoord
[meshX,meshY] = meshgrid(Xcoord,Ycoord);

% Finally, 利用griddata来插值,从xyz生成栅格数据
%最后一个为插值方法,包linear cubic natural nearest和v4等方法
%v4方法耗时长但较为准确
mehsU = griddata(X,Y,u,meshX,meshY,'v4'); 
% sufacing the solution
figure('name','usurf')
surf(meshX,meshY,mehsU);shading interp
hold on 

% maeshing the solution
figure('name', 'umesh')
mesh(meshX,meshY,mehsU)
colorbar;
hold on

  • 5
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值