%% % script States_distance. Read the file that contains % the names of the states and the lon-lat co-ordinates % of the mid-point of each state. Compute the distance % matrix (in km) of the states. % It computes the pair of closest and more distant states % B = importdata('datafileUSA.txt'); lat = B.data(:,1); lon = B.data(:,2); names = char(B.textdata) % lon(end-7)=[]; lat(end-7)=[]; names(end-7,:)=[]; D = distances(lon,lat); Dmin = min(min(D(D>0))) [k,j] = find(D==Dmin) disp(['minimum distance among states: km ' num2str(Dmin)]) disp('closest states pair: ') disp(names(k(1),:)) disp(names(j(1),:)) % Dmax = max(max(D(D>0))) [k,j] = find(D==Dmax) disp(['maximum distance among states: km ' num2str(Dmax)]) disp('farthest states pair: ') disp(names(k(1),:)) disp(names(j(1),:))