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

3 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2018-7-1
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 2018-7-2
1. yyyy/mm/dd hh:mm:ss 2. yes.I will handle after this loop 3. I used 2017a maltab.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by