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) -----------------------------------------

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. :/