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

2 ビュー (過去 30 日間)
xszm
xszm 2018 年 7 月 1 日
コメント済み: xszm 2018 年 7 月 2 日
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 Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by