필터 지우기
필터 지우기

How to combine 3 xyz data files

조회 수: 7 (최근 30일)
eevee
eevee 2014년 10월 20일
댓글: Charlotte Findlay 2019년 5월 2일
Hi,
I have 3 xyz data files (each contains longitude(z), latitude(y), and the water depth(z)). For my assignments, I have to combine these 3 xyz data files together to create a new bathymetry. I have tried the following codes, but matlab just crashed everytime i run it.
%%COMBINE 2014 XYZ DATA FILES
clear all; clc
a=load('bs_09092014_soundings-mean.pts');
b=load('bs_09092014_soundings_shoalest.pts');
c=load('bs_10092014-levels.pts');
% FIND THE MIN AND MAX AMONG THE 3 DATA FILES
% FIND X MIN
if ((min(a(:,1))>min(b(:,1))) && (min(a(:,1))>min(c(:,1))))
xmin=min(a(:,1));
else
if ((min(b(:,1))>min(a(:,1))) && (min(b(:,1))>min(c(:,1))))
xmin=min(b(:,1));
else
xmin=min(c(:,1));
end
end
% FIND X MAX
if ((max(a(:,1))<max(b(:,1))) && (max(a(:,1))<max(c(:,1))))
xmax=max(a(:,1));
else
if ((max(b(:,1))<max(a(:,1))) && (max(b(:,1))<max(c(:,1))))
xmax=max(b(:,1));
else
xmax=max(c(:,1));
end
end
% FIND Y MIN
if ((min(a(:,2))>min(b(:,2))) && (min(a(:,2))>min(c(:,2))))
ymin=min(a(:,2));
else
if ((min(b(:,2))>min(a(:,2))) && (min(b(:,2))>min(c(:,2))))
ymin=min(b(:,2));
else
ymin=min(c(:,2));
end
end
% FIND Y MAX
if ((max(a(:,2))<max(b(:,2))) && (max(a(:,2))>max(c(:,2))))
ymax=max(a(:,2));
else
if ((max(b(:,2))>max(a(:,2))) && (max(b(:,2))>max(c(:,2))))
ymax=max(b(:,2));
else
ymax=max(c(:,2));
end
end
% FIND THE INDICES BETWEEN XY MIN AND MAX, TO CREATE A NEW MATRIX THAT CONSISTS OF THE INTERSECTIONAL AREA OF ALL 3 XYZ FILES
aInd=find(a(:,1)>xmin & a(:,1)<xmax & a(:,2)>ymin & a(:,2)<ymax);
xa=a(aInd,1);
ya=a(aInd,2);
za=a(aInd,3);
bInd=find(b(:,1)>xmin & b(:,1)<xmax & b(:,2)>ymin & b(:,2)<ymax);
xb=b(bInd,1);
yb=b(bInd,2);
zb=b(bInd,3);
cInd=find(c(:,1)>xmin & c(:,1)<xmax & c(:,2)>ymin & c(:,2)<ymax);
xc=c(cInd,1);
yc=c(cInd,2);
zc=c(cInd,3);
xstep=linspace(xmin,xmax,1000);
ystep=linspace(ymin,ymax,1000);
[xia yia]=meshgrid(xstep,ystep);
zia=griddata(xa,ya,za,xia,yia);
[xib yib]=meshgrid(xstep,ystep);
zib=griddata(xb,yb,zb,xib,yib);
[xic yic]=meshgrid(xstep,ystep)'
zic=griddata(xc,yc,zc,xic,yic);
pcolor(xia,yia,zia);
shading interp
hold on
pcolor(xib,yib,zib);
shading interp
hold on
pcolor(xic,yic,zic);
shading interp
hold off
Thanks, Eve
  댓글 수: 1
Image Analyst
Image Analyst 2014년 10월 20일
For a true MATLAB crash (crash of the actual matlab.exe itself, and not just of your particular program), see the FAQ: http://matlab.wikia.com/wiki/FAQ#After_installation.2C_MATLAB_crashes_or_gives_an_error_message_when_I_try_to_run_MATLAB.

댓글을 달려면 로그인하십시오.

채택된 답변

Mohammad Abouali
Mohammad Abouali 2014년 10월 20일
편집: Mohammad Abouali 2014년 10월 20일
Follow this procedure:
1) load your three files into a,b,c variable
2) combine them into one variable:
x=[a(:,1),b(:,1),c(:,1)];
y=[a(:,2),b(:,2),c(:,2)];
z=[a(:,3),b(:,3),c(:,3)];
3) make a scattered intrpolant
F = scatteredInterpolant(x,y,z)
4) make a gridded region with proper spacing of your choice
minX=min(x);
maxX=max(x);
same goes for y; then make a regularly spaced grid:
[XGrid, YGrid]=ndgrid(minX:dx:maxX,minX:dx:maxX);
5) interpolate your data back to this area grid by calling
zGrid=F(XGrid,YGrid);
  댓글 수: 8
Mohammad Abouali
Mohammad Abouali 2014년 10월 22일
You are welcome.
Charlotte Findlay
Charlotte Findlay 2019년 5월 2일
Could I ask what the 'dx' component of this part of the code would be?
[XGrid, YGrid]=ndgrid(minX:dx:maxX,minX:dx:maxX);

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

j.D
j.D 2018년 5월 4일
Can this code work for two and what changes are needed if it can be used for two

카테고리

Help CenterFile Exchange에서 Orange에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by