clc
clear all
close all
% script :
% --------
for i=1:4
% for input file 1 : TDFstage12
if i==1
n=12;
end
% for input file 2 : TDFstage16
if i==2
n=16;
end
% for input file 3 : TDFstage17
if i==3
n=17;
end
% for input file 4 : TDFstage19
if i==4
n=19;
end
fn = strcat('TDFstage',num2str(n));
load(fn) % loading input file
[tot_dist , vert_speed] = processData(n,time,speed,elev); ?lling function
% result of total distance :
fprintf('Calculated Total Distance of Stage %d = %.3f \n\n',n,tot_dist(end));
end
% function :
% ----------
function [tot_dist , vert_speed] = processData(n,time,speed,elev)
% step 1 :
figure
subplot(2,1,1);
[ax,h1,h2] = plotyy(time,speed,time,elev); % plot window 1
temp = strcat('Speed and Elevation For Stage',num2str(n));
title(temp);
xlabel('Time (hrs)');
set(get(ax(1),'Ylabel'),'String','Speed (km/hr)');
set(get(ax(2),'Ylabel'),'String','Elevation (m)');
h1.LineWidth = 2;
h2.LineWidth = 2;
% step 2 :
tot_dist = cumtrapz(time,speed);
% step 3 :
vert_speed = diff(elev);
% step 4 :
subplot(2,1,2);
plot(time(1:end-1),vert_speed,'r','linewidth',2);
title('Vertical Speeds');
xlabel('Time (hrs)');
ylabel('Vertical speeds(m/hr)');
end