How to sum the fuel consumed at idle (vehicle speed=0)?

2 ビュー (過去 30 日間)
Kelsey
Kelsey 2014 年 7 月 15 日
コメント済み: Alaa Abdelaziz 2016 年 8 月 28 日
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 件のコメント
Kelsey
Kelsey 2014 年 7 月 15 日
Some modifications to my code...it still won't run, but hopefully this can help better clarify the logic I'm trying to achieve:
[ZeroSpeed, IdleFuelIndex] = min(VSPD); %index for when VSPD=0 (idle)
IdleFuelTime = time(IdleFuelIndex); %make the index be time
for n=1:length(time)-1
if t(n+1) = IdleFuelTime
IdleFuel(n+1) = Fuel_Consumed_Method2_L(n+1) + IdleFuel(n);
elseif t(n+1) ~= IdleFuelTime
IdleFuel(n+1) = 0 + IdleFuel(n);
end
end
Alaa Abdelaziz
Alaa Abdelaziz 2016 年 8 月 28 日
how can i detect the vehicle speed?

サインインしてコメントする。

回答 (2 件)

Yoav Livneh
Yoav Livneh 2014 年 7 月 15 日
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 件のコメント
Kelsey
Kelsey 2014 年 7 月 15 日
Thank you for your reponse! When I run just that code, however, I get NaN returned...any idea how to fix this?
Yoav Livneh
Yoav Livneh 2014 年 7 月 15 日
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
Kelsey 2014 年 7 月 15 日
This code seems to come close:
IdleFuelIndex = find(VSPD == 0); %(find indexes where VSPD=0)
IdleFuel = 0; %fuel consumed when car is at idle (L)
for n = IdleFuelIndex
IdleFuel(n) = Fuel_Consumed_Method2_L(n);
end
IdleFuel = transpose(IdleFuel);
IdleFuelTime = time(IdleFuelIndex);
IdleFuel = interp1(IdleFuelTime,IdleFuel,time);
...it returns the vector IdleFuel with seemingly legitimate data, but for some reason is one entry less than the rest of my data. I tried to solve this issue by interpolating using time as the index, but I get the error message, "The grid vectors do not define a grid of points that match the given values. Error in interp1 F = griddedInterpolant(X,V(:,1),method);"

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by