How to open multiple text file, execute sequentially, and save them as a txt file?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% Calculation of TC Translation speed
clc;clear;close all
data = load('file (1).txt');
radius = 6371;
N = pi/180;
lat = data(:,1)*N;
Lat1 = [];
for i = 1:2:length(lat)
lat1 = lat(i);
Lat1 = [lat1;Lat1];
end
Lat2 = [];
for j = 2:2:length(lat)
lat2 = lat(j);
Lat2 = [lat2;Lat2];
end
lon = data(:,2)*N;
Lon1 = [];
for k = 1:2:length(lon)
lon1 = lon(k);
Lon1 = [lon1;Lon1];
end
Lon2 = [];
for l = 2:2:length(lon)
lon2 = lon(l);
Lon2 = [lon2;Lon2];
end
deltaLat = Lat2-Lat1;
deltaLon = Lon2-Lon1;
a = sin((deltaLat)/2).^2 + ((cos(Lat1).*cos(Lat2)) .* sin(deltaLon/2).^2);
c = 2*atan2(sqrt(a),sqrt(1-a));
dis = (radius*c)*1000; % Haversine distance in m
len = length(dis);
time = linspace(3,3,len); % 3 hourly time increment
t = (time*3600)'; % hour to second
tran_speed = dis./t; % m/s
% converting original lat and lon
trans_lat = nanmean([Lat1 Lat2]')/N; %#ok<UDIM>
trans_lon = nanmean([Lon1 Lon2]')/N; %#ok<UDIM>
% add lat, lon, and translation speed in one file
trans_file1 = [trans_lat' trans_lon' tran_speed];
% save output as a text file
dlmwrite('trans_file1.txt',trans_file1,'delimiter','\t')
0 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Data Import and Analysis 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!