How to assign corresponding Z value to gridded X,Y data ?
30 次查看(过去 30 天)
显示 更早的评论
Hello all,
Having a problem with interpolating the data. I have a live data stream project where data comes from the serial port. After several steps, I want to create a XYZ grid from easting,northing and depth values.
Currently, script creates a surface in real time with "fit" function. 3D surface is visible in the figure and it is updating, so I reckon I have my interpolated surface. Then creating a meshgrid [X,Y] at interested grid size successfully. Then I tried to use "interp2" function to interpolate Z values at grid coordinates(created in meshgrid). But it's not working. Shared the error below as well. How can the matlab produce Z grid corresponding to the X Y grid (which is produced in meshgrid) ?
Kind Regards,
Alper
drawT=0;
while true
...
lla = [lla; Easting, Northing, Depth];
HRZntl=[lla(:,1) lla(:,2)];
if drawT == 10 % once every 10 input data
figure(1)
clf
[X, Y]=meshgrid(min(lla(:,1)):0.1:max(lla(:,1)), min(lla(:,2)):0.1:max(lla(:,2))); %Gridding the data at .1 meters
fitObj=fit(HRZntl,lla(:,3),'linearinterp'); % fitting the surface to my Easting, Northing and Depth data and it works
Z=interp2(lla(:,1),lla(:,2),lla(:,3),X,Y); % Giving Error here
plot(fitObj,HRZntl,lla(:,3));
drawT=0;
axis tight
grid on
end
end
Once this code runs, I receive the error below;
Error using griddedInterpolant
The number of input coordinate arrays must match the dimensions of the sample values.
Error in interp2>makegriddedinterp (line 226)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 126)
F = makegriddedinterp({X, Y}, V, method,extrap);
Error in RealTime_SBES_DataCollection_and_Mapping (line 108)
Z=interp2(lla(:,1),lla(:,2),lla(:,3),X,Y);
0 个评论
采纳的回答
Scott MacKenzie
2021-7-7
Try replacing interp2 with griddata, like this:
[X,Y] = meshgrid(min(lla(:,1)):0.1:max(lla(:,1)), min(lla(:,2)):0.1:max(lla(:,2)));
Z = griddata(lla(:,1),lla(:,2),lla(:,3),X,Y);
If the original data are in x, y, and z vectors, as is the case here, then griddata is the best choice for interpolation.
2 个评论
Scott MacKenzie
2021-7-7
@Mustafa Alper Cetintas You're welcome. Glad to help. Good luck with your research.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!