MATLAB Examples

# Access data from the fleet server, process, and visualize

## Contents

url = 'http://ec2-54-187-132-60.us-west-2.compute.amazonaws.com/api?user=anita.gajjala@mathworks.com'; filename = 'data.zip'; websave(filename,url); unzip(filename);

## Open File, select "Table", then "Import Selection"

```uiopen('20150115022155_logfile.csv',1) ```

## Convert to datetime

```logfile.time = datetime(logfile.time/1000,'ConvertFrom','posixtime')-hours(5); ```

## Create map

```% Plot the GPS tracks wmline(logfile.kff1006,logfile.kff1005,'Color',[0 1 1],'Width',6) % MathWorks Office lat = 42.299827; lon = -71.350273; description = sprintf('%s<br>%s</br><br>%s</br>',... '3 Apple Hill Drive', 'Natick, MA. 01760', ... 'http://www.mathworks.com'); name = 'The MathWorks, Inc.'; iconDir = fullfile(matlabroot,'toolbox','matlab','icons'); iconFilename = fullfile(iconDir, 'matlabicon.gif'); wmmarker(lat, lon, 'Description', description, ... 'FeatureName', name,... 'Icon', iconFilename,... 'OverlayName', name); % Add the fuel consumed as markers fuelVec = logfile.kff125a * 1/3785.41178; % Scale to range of 1:64 fuelScaled = scaleVector(fuelVec,[1 64],'integer'); fuelScaled(isnan(fuelScaled)) = 1; % Draw the colored markers cmap = jet(64); s = 5; % Grab every 5th data point wmmarker(logfile.kff1006(1:s:end),logfile.kff1005(1:s:end),... 'Color',cmap(fuelScaled(1:s:end),:)) ```

## Plot raw data

```% Speed, torque, RPM hA1 = subplot(5,1,1); speed = logfile.kff1001 * 1/1.60934; % Km/h to mi/h plot(logfile.time,logfile.kff1001 * 1/1.60934); ylabel(hA1,'Speed (mph)') title('Merging onto Route 9'); hA2 = subplot(5,1,2); plot(logfile.time(2:end),diff(speed)); ylabel(hA2,{'Acceleration';'(mph/s)'}) hold(hA2,'on'); plot(hA2,logfile.time,5*ones(size(logfile.time)),'r'); hold(hA2,'off') hA3 = subplot(5,1,3); plot(logfile.time,logfile.kc); ylabel(hA3,'Engine RPM') hA4 = subplot(5,1,4); plot(logfile.time,logfile.kff125a * 1/3785.41178); % Convert cc/min to gal/min ylabel(hA4,{'Fuel Flow';'(gal/min)'}) hA5 = subplot(5,1,5); plot(logfile.time,str2double(logfile.kff1225) * 1/0.7375621483695506); % Convert ft-lb to Nm ylabel(hA5,{'Torque';'(Nm)'}) % Link axes linkaxes([hA1,hA2,hA3,hA4,hA5],'x') ```