• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

MATLAB assistance

Joined
Dec 15, 2011
Messages
1,962 (0.44/day)
Location
Sydney NSW, Australia
System Name Shoebox Sandwich | Razer Blade 14 | Synology DS418 w/ 4X8TB WD Red | iPhone 15 Pro
Processor AMD Ryzen 7 7800X3D | AMD Ryzen 9 5900HX
Motherboard ASRock B650E PG-ITX WiFi | Razer thing
Cooling NZXT Kraken 240 RGB w/ Lian Li P28 + Corsair AF120 Slim | Double fan vapour chamber
Memory G.Skill Flare X5 2x16GB 6000MHz CL32 DDR5 | 16GB 3200MHz DDR4
Video Card(s) Sapphire Radeon RX 7900 XTX | NVIDIA GeForce RTX 3070 8GB
Storage Seagate FireCuda 520 2TB + Lexar NM790 4TB | 1TB NVMe SSD + 2TB NVMe external SSD
Display(s) Alienware AW3423DW & Sony A90K 42" | 14" QHD IPS 165Hz & Sony X90J 65" 4K TV
Case FormD T1 - v2.1 - Titanium colourway w Aluminium mesh | Razer Blade 14
Audio Device(s) Schiit Hel 2E (Focal Clear & HiFiMAN HE-4XX & DROP PC38X) | Samsung Q950A
Power Supply Corsair SF750 Platinum | Razer 230W brick
Mouse Razer Viper Ultimate Mercury | Roccat Kain 202
Keyboard DIY Geek 64 PCB (Kailh Box Deep Sea - Matcha XDA Keycaps) | Corsair K63
VR HMD Oculus Quest
Software Windows 11 Home | Windows 11 Home
Benchmark Scores 2022 MINI Countryman SE PHEV Hybrid ALL4 | British Racing Green| Malt Brown Interior| YOURS Trim
Hi all,

I'm having a problem with my MATLAB code I AM A NOOB TO PLEASE BE KIND D: (see below, I've pasted it). Now in the top code, this is my original one except I get no values for TTC (doesn't even appear in the workspace). So I did a bit of experimenting as I find trial and error usually sorts me out but I don't think it did this time. The bottom code is my experimental code, and I get the right number of values for TTC (1464x1) which is good as my excel file has 1464 values. Everything is fine but the TTC values I just can't get :/ If I could get some assistance that would be very much appreciated.


%assignment Problem 2

clc;
clear;
close;

%TTC means Time-To-Collision (s)
%Vf is the speed of the following vehicle (m/s)
%Vl is the speed of the leading vehicle (m/s)
%Ll is the length of the leading vehicle (m)
%t is the time headway

a=xlsread('data_Problem2_Traffic_raw.xls');


%b=a:),1); %car
Vf=a:),2); %Vf
Vl=a:),3); %Vl
Ll=a:),4); %Ll
t=a:),5); %t
i=0;


d=(t.*Vf)-Ll; % see method for algebraic conversion from t=(d+Ll)/Vf


for i=1:length(d)
if (Vf-Vl)>0
TTC(i)=(d(i)./(Vf-Vl))
fprintf('TTC is equal to %f\n', TTC)
if TTC(i)<1
disp('The safety level is very dangerous')
elseif TTC(i)>1 && TTC(i)<4
disp('The safety level is dangerous')
elseif TTC(i)>4
disp('The safety level is safe')
end
if (TTC(i)<1)<0.03 && (TTC(i)>4)>0.8
disp('The road section is safe')
else
disp('The road section is not safe')
end
elseif (Vf-Vl)<=0
%break
TTC(i)=inf;

end

end
fprintf('displaying TTC equals %f\n', TTC)

-------------------------------------

%assignment Problem 2

clc;
clear;
close;

%TTC means Time-To-Collision (s)
%Vf is the speed of the following vehicle (m/s)
%Vl is the speed of the leading vehicle (m/s)
%Ll is the length of the leading vehicle (m)
%t is the time headway

a=xlsread('data_Problem2_Traffic_raw.xls');


%b=a:),1); %car
Vf=a:),2); %Vf
Vl=a:),3); %Vl
Ll=a:),4); %Ll
t=a:),5); %t
i=0;
TTC=0;

d=(t.*Vf)-Ll; % see method for algebraic conversion from t=(d+Ll)/Vf
TTC=(d./(Vf-Vl))

for i=1:length(d)
if (Vf-Vl)>0
TTC(i)=(d(i)./(Vf-Vl))
fprintf('TTC is equal to %f\n', TTC)
if TTC(i)<1
disp('The safety level is very dangerous')
elseif TTC(i)>1 && TTC(i)<4
disp('The safety level is dangerous')
elseif TTC(i)>4
disp('The safety level is safe')
end
if (TTC(i)<1)<0.03 && (TTC(i)>4)>0.8
disp('The road section is safe')
else
disp('The road section is not safe')
end
elseif (Vf-Vl)<=0
%break
TTC(i)=inf;

end

end
fprintf('displaying TTC equals %f\n', TTC)

-----------------------------------------
 
Joined
Feb 18, 2010
Messages
1,850 (0.36/day)
System Name Eldritch
Processor AMD Ryzen 5 5800X3D
Motherboard ASUS TUF X570 Pro Wifi
Cooling Satan's butthole after going to Taco Bell
Memory 64 GB G.Skill TridentZ
Video Card(s) Vega 56
Storage 6*8TB Western Digital Blues in RAID 6, 2*512 GB Samsung 960 Pros
Display(s) Acer CB281HK
Case Phanteks Enthoo Pro PH-ES614P_BK
Audio Device(s) ASUS Xonar DX
Power Supply EVGA Supernova 750 G2
Mouse Razer Viper 8K
Software Debian Bullseye
Use code tags.
 
Joined
Dec 15, 2011
Messages
1,962 (0.44/day)
Location
Sydney NSW, Australia
System Name Shoebox Sandwich | Razer Blade 14 | Synology DS418 w/ 4X8TB WD Red | iPhone 15 Pro
Processor AMD Ryzen 7 7800X3D | AMD Ryzen 9 5900HX
Motherboard ASRock B650E PG-ITX WiFi | Razer thing
Cooling NZXT Kraken 240 RGB w/ Lian Li P28 + Corsair AF120 Slim | Double fan vapour chamber
Memory G.Skill Flare X5 2x16GB 6000MHz CL32 DDR5 | 16GB 3200MHz DDR4
Video Card(s) Sapphire Radeon RX 7900 XTX | NVIDIA GeForce RTX 3070 8GB
Storage Seagate FireCuda 520 2TB + Lexar NM790 4TB | 1TB NVMe SSD + 2TB NVMe external SSD
Display(s) Alienware AW3423DW & Sony A90K 42" | 14" QHD IPS 165Hz & Sony X90J 65" 4K TV
Case FormD T1 - v2.1 - Titanium colourway w Aluminium mesh | Razer Blade 14
Audio Device(s) Schiit Hel 2E (Focal Clear & HiFiMAN HE-4XX & DROP PC38X) | Samsung Q950A
Power Supply Corsair SF750 Platinum | Razer 230W brick
Mouse Razer Viper Ultimate Mercury | Roccat Kain 202
Keyboard DIY Geek 64 PCB (Kailh Box Deep Sea - Matcha XDA Keycaps) | Corsair K63
VR HMD Oculus Quest
Software Windows 11 Home | Windows 11 Home
Benchmark Scores 2022 MINI Countryman SE PHEV Hybrid ALL4 | British Racing Green| Malt Brown Interior| YOURS Trim
Thanks hellrazor, it's ok though because I found my problem. I needed another if/else statement for the d value :) I obviously wasn't functioning too well at 11pm. :/
 
Top