I want to match multi-filed's data in two structure data.

1 visualización (últimos 30 días)
xszm
xszm el 1 de Jul. de 2018
Comentada: xszm el 2 de Jul. de 2018
I have two stuctures data showing as two pictures,and I want to find the data that meets the conditions to match. Using the loop is very slow. Please give me some better advice.Thanks.
if true
for i= 1:length(ap.date)
dnb = datevec(ap.date(i));
lonb=ap.lon(i);
latb=ap.lat(i);
for j=1:length(ad.date)
dna = datevec(ad.date(j));
lona=ad.lon(j);
lata=ad.lat(j);
difftime=fix(etime(dna,dnb)/3600);
difflon=lonb-lona;
difflat=latb-lata;
if (difftime>=-0.05 & difftime <=0.05 & difflon>=-0.001 & difflon <=0.001 & difflat>=-0.001 & difflat <=0.001)==1
temp=[i j]; w=[w;temp];
re_data.date(i,1)=ap.date(i);
re_data.lon(i,1)=ap.lon(i);
re_data.lat(i,1)=ap.lat(i);
re_data.date_ad(i,1)=ad.date(j);
re_data.lon_ad(i,1)=ad.lon(j);
re_data.lat_ad(i,1)=ad.lat(j);
re_data.cruise_ad(i,1)=ad.cruise(j);
re_data.depth_ad(i,1)=ad.depth(j);
elseif difftime>=-0.05 & difftime <=0.05 & difflon>=-0.001 & difflon <=0.001 & difflat>=-0.001 & difflat <=0.001
re_data.date(i,1)=ap.date(i);
re_data.lon(i,1)=ap.lon(i);
re_data.lat(i,1)=ap.lat(i);
re_data.date_ad(i,1)={-999};
re_data.lon_ad(i,1)=-999;
re_data.lat_ad(i,1)=-999;
re_data.cruise_ad(i,1)={-999};
re_data.depth_ad(i,1)=-999;
end
end
end
  3 comentarios
Guillaume
Guillaume el 1 de Jul. de 2018
What format is the time in the cell arrays, datestr?
What should happen if there is more than one match in ad for a single ap? Or is it guaranteed that it never happens?
Any reason you're using old matlab time functions instead of modern datetime? Which version are you using?
xszm
xszm el 2 de Jul. de 2018
1. yyyy/mm/dd hh:mm:ss 2. yes.I will handle after this loop 3. I used 2017a maltab.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by