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.
I want to match multi-filed's data in two structure data.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191596/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/191597/image.png)
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 commentaires
Guillaume
le 1 Juil 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?
Réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!