How to sum the fuel consumed at idle (vehicle speed=0)?
Mostrar comentarios más antiguos
I have some vectors of data for time, vehicle fuel consumption, and vehicle speed for a certain driving trip. I am confused about how to tell Matlab to sum up the fuel used for all time when vehicle speed=0...any help with this would be sincerely and greatly appreciated! Here is what I have right now:
[ZeroSpeed, IdleFuelIndex] = min(VSPD);
IdleFuelTime = time(IdleFuelIndex);
IdleFuel=0;
for n=1:length(time)-1
IdleFuel(n+1) = Fuel_Consumed(IdleFuelTime)(n+1) + IdleFuel(n);
end
min(VSPD)=0, so IdleFuelTime should return the times when VSPD=0. (VSPD is the variable for vehicle speed). The problem is, Matlab is only returning for the first time that vehicle speed is zero! Also, I'm not sure about the for loop...perhaps I'm on the right track though? IdleFuel (the fuel consumed while the vehihcle is idling) is supposed to be equal to the summation of the fuel consumed by the vehicle at IdleFuelTime (whenever VSPD=0).
Thank you so much for your help with this, in advance! I'm really stuck on this.
2 comentarios
Kelsey
el 15 de Jul. de 2014
Alaa Abdelaziz
el 28 de Ag. de 2016
how can i detect the vehicle speed?
Respuestas (2)
Yoav Livneh
el 15 de Jul. de 2014
In order to get all indeces of speed=0 you need to do:
IdleFuelIndex = find(VSPD == 0);
Then you can add them all up:
IdleFuel = sum(Fuel_Consumed(IdleFuelIndex));
2 comentarios
Kelsey
el 15 de Jul. de 2014
Yoav Livneh
el 15 de Jul. de 2014
It's hard to know exactly where the problem is without seeing the data. Make sure all the data is correct and valid. You can also use cumsum instead of sum to see where the NaN appears.
Kelsey
el 15 de Jul. de 2014
Categorías
Más información sobre Matrix Indexing en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!