For loop with multiple arrays

2 次查看(过去 30 天)
Vinay Srinivasan
Vinay Srinivasan 2019-10-6
Hello Everyone ,I have to determine fuel_consumption at 60,80 ,120 and maximum speed. Fuel consumption is function of sfc,powerclutch and speed which is varying and the rest are constant.How to use for loop in this condition istead of writing 4 times .Can someone advice me please !
mtf.png
  2 个评论
the cyclist
the cyclist 2019-10-6
It's easier for us to help you if you paste your code as text (not an image of your code), because then we can copy & paste it into MATLAB for editing.
Vinay Srinivasan
Vinay Srinivasan 2019-10-6
Powerclutch [8771.71680000000 14371.2576000000 33023.8944000000 242500.000000000]
%60 km/hr
sfc_60=600; %% SFC in g/kwh
fuel_consumption60= (sfc_60*Powerclutch(1)*100/1000)/(1000*Rho_fuel*60); %fuel consumption in litre/100km
%80km/hr
sfc_80=450;
fuel_consumption80= (sfc_80*Powerclutch(2)*100/1000)/(1000*Rho_fuel*80); %fuel consumption in litre/100km
%120 km/hr
sfc_120=330;
fuel_consumption120= (sfc_120*Powerclutch(3)*100/1000)/(1000*Rho_fuel*120);
%maximum speed
sfc_maximumspeed=360;
fuel_consumptionmaxspeed= (sfc_maximumspeed*Powerclutch(4)*100/1000)/(1000*Rho_fuel*maximum_speed);

请先登录,再进行评论。

回答(1 个)

the cyclist
the cyclist 2019-10-6
编辑:the cyclist 2019-10-6
You don't need a loop:
% These are tot defined in your code, so I made up some numbers
max_speed = 180;
Rho_fuel = 1;
Powerclutch = [8771.7168 14371.2576 33023.8944 242500];
speed = [60 80 120 max_speed];
sfc = [600 450 330 360];
fuelConsumption = (sfc.*Powerclutch*100/1000)./(1000*Rho_fuel*speed);
This calculates all four values in vectorized form.

类别

Help CenterFile Exchange 中查找有关 Graph and Network Algorithms 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by