MATLAB Project_Rolle
Contents
INTRODUCTION
disp('You live in the heart of California....') pause(2) disp("Which is known for it's traffic and potential accidents..") pause(2) disp("You have a fear of getting into a car crash..") pause(2) disp('This program will inform you on which factors increase your likeihood of getting into an accident.') pause(2) disp('Enjoy ;)') pause (10)
You live in the heart of California.... Which is known for it's traffic and potential accidents.. You have a fear of getting into a car crash.. This program will inform you on which factors increase your likeihood of getting into an accident. Enjoy ;)
TABLES & Graphs: General Info
clear;clc;data = load("Download1stDataforMATLABProject-traffic-crashes.mat"); data = data.trafficcrashes1; data.Properties.VariableNames{'V1Driver'}='Age'; data.Properties.VariableNames{'V1Type'}='VehicleType'; data.Properties.VariableNames{'FactorsRo'}='RoadCond'; data.Properties.VariableNames{'Distance'}='LengthofHazardArea'; rows = data(:,[9 21 41 19 42 12]);%Display Info in Table head(rows,5) pause(20)
%Age age= rows(:,2); A1=table2array(age); subplot(2,2,1) histogram(A1,6),title('Age of Driver') %RoadCond A2=rows(:,3); aa2=table2array(A2); RoadCond=categorical(aa2); summary(RoadCond); subplot(2,2,2) histogram(RoadCond), title('Road Condition') %Weather A4= rows(:,6); aa4=table2array(A4); weather=categorical(aa4); subplot(2,2,3) histogram(weather), title('Weather Condition') %Sun A5= rows(:,5); aa5=table2array(A5); sun=categorical(aa5); subplot(2,2,4) histogram(sun), title('Light') hold off pause(20)
%Distance figure(2) distance= rows(:,1); %12720 rows(accidents) A6=table2array(distance); x=1:12720; y=A6; plot(x,y,x,mean(A6),'ko');title('Distance of Accident');ylabel('Distance(m)'); text(6000,1000,'Average= 247.44') hold off %Table of Distance pause(10) b=mode(A6);c=mean(A6);d=min(A6);e=max(A6); disp('Description of Length(m) of All Accidents Reported') disp(' Mode Mean Min Max') disp({b,c,d,e}) pause(5)
LengthofHazardArea Age RoadCond VehicleType Lighting Weather ____________________ ___ _________ _________________ __________________________ _______15 49 DRY HATCHBACK, 4 DOOR DAYLIGHT CLEAR 0 22 DRY SEDAN, 4 DOOR DARK - NO LIGHTING CLEAR 195 22 DRY SEDAN, 2 DOOR DARK - CONTINUOUS LIGHTING CLEAR 500 0 WET SEDAN DARK - SPOT LIGHTING CLEAR 0 27 DRY SEDAN, 4 DOOR DARK - NO LIGHTING CLEAR DRY 10315 ICE 1 NA 1354 OTHER 1 SNOW 1 UNKNOWN 1 WET 1047Description of Length(m) of All Accidents Reported Mode Mean Min Max {[0]} {[247.4438]} {[0]} {[5800]}
Continue: Logical Function
disp('This information may be overwhelming...') pause(3) play=input("Would you like the data to be tailored to you? '1' for yes or '0' for no? \n"); while play<1 %%Loop if play==1 break elseif play==0 msg='End of Program Exit Now' assert(error(msg)) end end
This information may be overwhelming...
Error using input Cannot call INPUT from EVALC.Error in MATLABProject (line 76) play=input("Would you like the data to be tailored to you? '1' for yes or '0' for no? \n");
Information tailored to them..(Menus)
Age Menu
age= rows(:,2); A1=table2array(age);
youngadult=100-length(find(A1<18 | A1>29))/length(A1)*100;
middle_age=100-length(find(A1<30 | A1>45))/length(A1)*100;
middle_age2=100-length(find(A1<46 | A1>59))/length(A1)*100;
old_adult=100-length(find(A1<60 | A1>100))/length(A1)*100;
agegroup={youngadult middleage middleage2
oldadult}; age1=menu('How old are
you?','18-29','20-45','46-59','60-100');
disp('This is percentage is how likely you are to
get into an accident:') disp(agegroup(age1))
Function table
function data_table() clear;clc;data = load("Download1stDataforMATLABProject-traffic-crashes.mat"); data = data.trafficcrashes1; data.Properties.VariableNames{'V1Driver'}='Age'; data.Properties.VariableNames{'V1Type'}='VehicleType'; data.Properties.VariableNames{'FactorsRo'}='RoadCond'; data.Properties.VariableNames{'Distance'}='LengthofHazardArea'; rows = data(:,[9 21 41 19 42 12])%Display Info in Table
return end