Hi, i have problem with my code, i have 85X10 double, that first and second rows are latitude and longitude, other 85X1 double is the days between each events. i need to calculate distance of each event and remove event with distance(Km) >=0 & <=5 and days between Days>=0 && Days<=7. i wrote something but still left events with that condition. i need your help
radius = 6371;Fd = [];s = 1;for i = 1: length(CatTd)-1 for ii = 2:length(CatTd)-1if CatTd(i,3:4) == CatTd(ii,3:4) % Row 3(Year) Row 4(Month)
lat1 = CatTd(i,2)*pi/180; lat2 = CatTd(ii,2)*pi/180;lon1 = CatTd(i,1)*pi/180; lon2 = CatTd(ii,1)*pi/180;deltaLat1 = lat2-lat1; deltaLon1 = lon2-lon1;x = deltaLon1*cos((lat1+lat2)/2); y = deltaLat1;Dkm = radius*sqrt(x*x + y*y); % Distance(Km)
else i = i+1; ii = i+1;lat1 = CatTd(i,2)*pi/180; lat2 = CatTd(ii,2)*pi/180;lon1 = CatTd(i,1)*pi/180; lon2 = CatTd(ii,1)*pi/180;deltaLat1 = lat2-lat1; deltaLon1 = lon2-lon1;x = deltaLon1*cos((lat1+lat2)/2); y = deltaLat1;Dkm = radius*sqrt(x*x + y*y); % Distance(Km) endif Dkm>=0 && Dkm<=5Fd(s) = i; Fd(s+1) = ii; s = s+2;endwhile ii == length(CatTd) i = i+1; ii = i+1; endwhile i == length(CatTd) ii = ii+1; endend endendend
Best Answer