Skip to content

Instantly share code, notes, and snippets.

@achalddave
Created November 7, 2014 02:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save achalddave/e7bbeb5f0745482bbed7 to your computer and use it in GitHub Desktop.
Save achalddave/e7bbeb5f0745482bbed7 to your computer and use it in GitHub Desktop.
function [C,N]=DataPerVeh(dt,VehId,Activity,cons)
%VehId
%dt=10
%Activity
%cons=[145.83; 163.7 ;223.62; 138.3]
ActivityId=find((Activity{2:end,1}==VehId));
VehActivity=Activity(ActivityId+1,:);
Nt=round(24/dt);
N=zeros(1,Nt);
C=zeros(1,Nt);%W
j=1;
tstep=1;
while j<size(VehActivity)-1
if tstep*dt<=VehActivity{j,4}
if strcmp(VehActivity{j,2},'Charging')
else
N(1,tstep)=1;
if strcmp(VehActivity{j,2},'Driving')
factor=VehActivity{j,5}*1.6/(VehActivity{j,4}-VehActivity{j,3});%km/h
if strcmp(VehActivity{j,6},'UDDS')
C(1,tstep)=cons(1)*factor;
elseif strcmp(VehActivity{j,6},'HWFET')
C(1,tstep)=cons(2)*factor;
elseif strcmp(VehActivity{j,6},'US06')
C(1,tstep)=cons(3)*factor;
else
C(1,tstep)=cons(4)*factor;
end
end
end
tstep=tstep+1;
else
if strcmp(VehActivity{j,2},'Charging')
else
N(1,tstep)=1;
if strcmp(VehActivity{j,2},'Driving')
factor=VehActivity{j,5}*1.6/(VehActivity{j,4}-VehActivity{j,3});%km/h
if strcmp(VehActivity{j,6},'UDDS')
C(1,tstep)=C(1,tstep)+cons(1)*factor;
elseif strcmp(VehActivity{j,6},'HWFET')
C(1,tstep)=C(1,tstep)+cons(2)*factor;
elseif strcmp(VehActivity{j,6},'US06')
C(1,tstep)=C(1,tstep)+cons(3)*factor;
else
C(1,tstep)=C(1,tstep)+cons(4)*factor;
end
end
end
j=j+1;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment