% daily mean speed.m
clc
clear

% load variables
load 2014-03-31/monday_31_03.mat;

% gps coordinates of Vienna north-east corner
ne_x = 48.292079905275806;
ne_y = 16.56538598632801;
% gps coordinates of Vienna south-west corner
sw_x = 48.09216946074534;
sw_y = 16.195977050781266;

% define needed variables
speed = 0;
j = 0;
avg_speed = 0;

% loop through the whole data set for the given day
for i = 1:length(m_id)
    
    % check whether the vehicle's gps coordinates are within Vienna region
    if (m_x(i) >= sw_y && m_x(i) <= ne_y) && (m_y(i) >= sw_x && m_y(i) <= ne_x)
        
        % sum the actual speed
        speed = speed + m_speed(i);
        
        % increment
        j = j + 1;
        
    end
    
end

% average speed for given day
avg_speed = speed / j;