How to combine 3 xyz data files
7 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
eevee
am 20 Okt. 2014
Kommentiert: Charlotte Findlay
am 2 Mai 2019
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 Kommentar
Image Analyst
am 20 Okt. 2014
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.
Akzeptierte Antwort
Mohammad Abouali
am 20 Okt. 2014
Bearbeitet: Mohammad Abouali
am 20 Okt. 2014
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 Kommentare
Charlotte Findlay
am 2 Mai 2019
Could I ask what the 'dx' component of this part of the code would be?
[XGrid, YGrid]=ndgrid(minX:dx:maxX,minX:dx:maxX);
Weitere Antworten (1)
j.D
am 4 Mai 2018
Can this code work for two and what changes are needed if it can be used for two
0 Kommentare
Siehe auch
Kategorien
Mehr zu Orange finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!