% velocity histogram.m
clc
clear

% load variables for Monday, 24 March
load 2014-03-24/monday_24_03.mat;

% define time slots for velocity values
speed_val = 0;
speed_num = 0;
speeds = [];

% 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 counters
SpeedValues=zeros(1,15);

% 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)
        
        hours = str2num(substring(m_time{i},11,13));
        
        if hours == 6
        
            % count the number of records left
            j = j + 1;
            
            % assign the speed of the given sample
            speed = m_speed(i);

            % store the speed in its speed cluster
            if speed < 1
                SpeedValues(1) = SpeedValues(1) + 1;
            elseif speed >= 1 && speed < 10
                SpeedValues(2) = SpeedValues(2) + 1;
            elseif speed >= 10 && speed < 20
                SpeedValues(3) = SpeedValues(3) + 1;
            elseif speed >= 20 && speed < 30
                SpeedValues(4) = SpeedValues(4) + 1;
            elseif speed >= 30 && speed < 40
                SpeedValues(5) = SpeedValues(5) + 1;
            elseif speed >= 40 && speed < 50
                SpeedValues(6) = SpeedValues(6) + 1;
            elseif speed >= 50 && speed < 60
                SpeedValues(7) = SpeedValues(7) + 1;
            elseif speed >= 60 && speed < 70
                SpeedValues(8) = SpeedValues(8) + 1;
            elseif speed >= 70 && speed < 80
                SpeedValues(9) = SpeedValues(9) + 1;
            elseif speed >= 80 && speed < 90
                SpeedValues(10) = SpeedValues(10) + 1;
            elseif speed >= 90 && speed < 100
                SpeedValues(11) = SpeedValues(11) + 1;
            elseif speed >= 100 && speed < 110
                SpeedValues(12) = SpeedValues(12) + 1;
            elseif speed >= 110 && speed < 120
                SpeedValues(13) = SpeedValues(13) + 1;
            elseif speed >=120 && speed < 150
                SpeedValues(14) = SpeedValues(14) + 1;
            else
                SpeedValues(15) = SpeedValues(15) + 1;
            end
        
        end
        
    end
    
end