SlideShare a Scribd company logo
1 of 3
%Coursework of Matlab
clc
clear
%%%% answer to question (a)
data=load('road_data.txt');
%put the first column of data(time in seconds) into variable T
T=data(:,1);
%put the second column of data(Sin km/h)into variable S
S=data(:,2);
%%%%% answer for question (b)
%speed=S*0.277777
speed=(S/3600)*1000;
%this will display my speed in meter per second
figure (1);
plot(T,speed,'ro-','MarkerFaceColor','y')
%label x axis as:Time (seconds)
xlabel('Time(seconds)')
%label y axis as:Speed into meter/seconds
ylabel('speed(meter/seconds)')
%gives a title tothe graph:
title('Graph showing speed vs Time')
%%%%%%%%%%%% answer for questin (c)
%convert the S vector from kmeter per hours to miles per hours
S_mph = S /1.609344;
%calculates the mean
Mean_S = mean(S_mph);
%show the mixmum value
Max_S = max(S_mph);
%writes and displayes "Average speed=X Miles/Hour" where X is mean value
%computed by matlab code,
Ave_Speed_disp=['Average speed = ', num2str(Mean_S,'%.2f'), 'miles per hour'];
disp (Ave_Speed_disp)
%stores the string "Maximum speed= X Miles/Hour"
fprintf ('Maximum Speed = %.2f miles/hourn', Max_S)
%%%%%%%%%%%%%%% answer to question (d)
total=length(S);%this command shows how many values are in the S column
zeros=sum(S==0);%this shows how many zeros there are in the S column
p=sum(S==0)/total*100;
% With the information I have this calculation works out how long the
% car has been in a stable position
fprintf('The car was stationary = %f percent of the time',p)
%%%% answer to question (e)
acceleration=diff(S)./diff(T);
acceleration2=[0;acceleration];
plot(T,acceleration2,'-mo','markerfacecolor','g') % plot the grips in the
xlabel('T(sec)') %labels the X axis of the graph
ylabel('acceleration(m/sec^2)') % labels the Y axis of the graph
title('Acceleration Vs Time') % Title of the graph
%%%%%% answer for question (f)
distance = cumtrapz(T,S);
grid on
dist2 = 0;
fori=1:length(S)-1
dist2(i+1)=dist2(i)+(S(i)+S(i+1))*(T(i+1)-T(i))/2;
end;
plot(T,distance);
title('Distance Vs Time')
xlabel('Time/Seconds')
ylabel('Km')
%%%% answer question (g)
Y = sum(S>65);
fprintf('n The speed limit was exceeded %ftime',Y);

More Related Content

Similar to Matlab instructions

Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
meerobertsonheyde608
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
smile790243
 
LAB05ex1.mfunction LAB05ex1m = 1; .docx
LAB05ex1.mfunction LAB05ex1m = 1;                          .docxLAB05ex1.mfunction LAB05ex1m = 1;                          .docx
LAB05ex1.mfunction LAB05ex1m = 1; .docx
smile790243
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
Abi finni
 
Dct compressionfactor8.doc
Dct compressionfactor8.docDct compressionfactor8.doc
Dct compressionfactor8.doc
MITTU1
 
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
Idabagus Mahartana
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
anhlodge
 

Similar to Matlab instructions (20)

Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdfConsider a 4-Link robot manipulator shown below. Use the forward kine.pdf
Consider a 4-Link robot manipulator shown below. Use the forward kine.pdf
 
Computation Assignment Help
Computation Assignment Help Computation Assignment Help
Computation Assignment Help
 
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docxLab 5 template  Lab 5 - Your Name - MAT 275 Lab The M.docx
Lab 5 template Lab 5 - Your Name - MAT 275 Lab The M.docx
 
ENGINEERING SYSTEM DYNAMICS-TAKE HOME ASSIGNMENT 2018
ENGINEERING SYSTEM DYNAMICS-TAKE HOME ASSIGNMENT 2018ENGINEERING SYSTEM DYNAMICS-TAKE HOME ASSIGNMENT 2018
ENGINEERING SYSTEM DYNAMICS-TAKE HOME ASSIGNMENT 2018
 
cruise control system
cruise control systemcruise control system
cruise control system
 
LAB05ex1.mfunction LAB05ex1m = 1; .docx
LAB05ex1.mfunction LAB05ex1m = 1;                          .docxLAB05ex1.mfunction LAB05ex1m = 1;                          .docx
LAB05ex1.mfunction LAB05ex1m = 1; .docx
 
Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
matlab.docx
matlab.docxmatlab.docx
matlab.docx
 
Etienne_ME_a241ms
Etienne_ME_a241msEtienne_ME_a241ms
Etienne_ME_a241ms
 
Dct compressionfactor8.doc
Dct compressionfactor8.docDct compressionfactor8.doc
Dct compressionfactor8.doc
 
Ece 415 control systems, fall 2021 computer project 1
Ece 415 control systems, fall 2021 computer project  1 Ece 415 control systems, fall 2021 computer project  1
Ece 415 control systems, fall 2021 computer project 1
 
curve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptxcurve fitting or regression analysis-1.pptx
curve fitting or regression analysis-1.pptx
 
MATLAB Scripts - Examples
MATLAB Scripts - ExamplesMATLAB Scripts - Examples
MATLAB Scripts - Examples
 
Advance Control System MatLab & Simulink codes with outputs
Advance Control System MatLab & Simulink codes with outputsAdvance Control System MatLab & Simulink codes with outputs
Advance Control System MatLab & Simulink codes with outputs
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
High Bandwidth suspention modelling and Design LQR Full state Feedback Contro...
 
Plotting position and velocity
Plotting position and velocityPlotting position and velocity
Plotting position and velocity
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Suspension_report
Suspension_reportSuspension_report
Suspension_report
 
Matlab1
Matlab1Matlab1
Matlab1
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Recently uploaded (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 

Matlab instructions

  • 1. %Coursework of Matlab clc clear %%%% answer to question (a) data=load('road_data.txt'); %put the first column of data(time in seconds) into variable T T=data(:,1); %put the second column of data(Sin km/h)into variable S S=data(:,2); %%%%% answer for question (b) %speed=S*0.277777 speed=(S/3600)*1000; %this will display my speed in meter per second figure (1); plot(T,speed,'ro-','MarkerFaceColor','y') %label x axis as:Time (seconds) xlabel('Time(seconds)') %label y axis as:Speed into meter/seconds ylabel('speed(meter/seconds)') %gives a title tothe graph: title('Graph showing speed vs Time') %%%%%%%%%%%% answer for questin (c) %convert the S vector from kmeter per hours to miles per hours
  • 2. S_mph = S /1.609344; %calculates the mean Mean_S = mean(S_mph); %show the mixmum value Max_S = max(S_mph); %writes and displayes "Average speed=X Miles/Hour" where X is mean value %computed by matlab code, Ave_Speed_disp=['Average speed = ', num2str(Mean_S,'%.2f'), 'miles per hour']; disp (Ave_Speed_disp) %stores the string "Maximum speed= X Miles/Hour" fprintf ('Maximum Speed = %.2f miles/hourn', Max_S) %%%%%%%%%%%%%%% answer to question (d) total=length(S);%this command shows how many values are in the S column zeros=sum(S==0);%this shows how many zeros there are in the S column p=sum(S==0)/total*100; % With the information I have this calculation works out how long the % car has been in a stable position fprintf('The car was stationary = %f percent of the time',p) %%%% answer to question (e) acceleration=diff(S)./diff(T); acceleration2=[0;acceleration]; plot(T,acceleration2,'-mo','markerfacecolor','g') % plot the grips in the
  • 3. xlabel('T(sec)') %labels the X axis of the graph ylabel('acceleration(m/sec^2)') % labels the Y axis of the graph title('Acceleration Vs Time') % Title of the graph %%%%%% answer for question (f) distance = cumtrapz(T,S); grid on dist2 = 0; fori=1:length(S)-1 dist2(i+1)=dist2(i)+(S(i)+S(i+1))*(T(i+1)-T(i))/2; end; plot(T,distance); title('Distance Vs Time') xlabel('Time/Seconds') ylabel('Km') %%%% answer question (g) Y = sum(S>65); fprintf('n The speed limit was exceeded %ftime',Y);