Clear Filters
Clear Filters

Varying multiple model inputs in MATLAB loop

2 views (last 30 days)
Hi,
I'm modelling the performance of a car in terms of fuel efficiency using various input parameters (e.g. mass, frontal area etc.) My code loops through time as the car accelerates and reaches a constant velocity. At the moment I have a loop outside of this that varies the model parameters one at a time and I am trying to plot the result of each of these input variations on the one graph but I can't seem to get it to work. The model will plot the last iteration of the loop (I.E Mass, as seen below) but none of the others even though I used hold on. Any help would be greatly appreciated!! Thanks.
for HH = 1:4
for k = 1:40
if (HH==1)
FrontalArea(k)=0.25+0.01*k;
else
FrontalArea(k)=0.4; %0.25-0.4-0.65 m^2
end
if (HH==2)
CoeffRoll(k)=0.001+0.0001*k; %0.001-0.003-0.005
else
CoeffRoll(k)=0.003;
end
if (HH==3)
CoeffDrag(k)=0.15+k*0.0075; %0.15-0.3-0.45
else
CoeffDrag(k)=0.3;
end
if (HH==4)
mass(k)=60+k*2; %60-100-140
else
mass(k)=100; %kg
end
for n=1:5000
%% Here is the loop modelling the car performance over time
end
if (HH==1)
plot(FrontalArea,FuelEff)
xlabel('Normalised Data');
ylabel('Fuel Efficiency (km/kWh)');
title('');
hold on
elseif (HH==2)
plot(CoeffRoll,FuelEff)
xlabel('Normalised Data');
ylabel('Fuel Efficiency (km/kWh)');
title('');
hold on
elseif (HH==3)
plot(CoeffDrag,FuelEff)
xlabel('Normalised Data');
ylabel('Fuel Efficiency (km/kWh)');
title('');
hold on
elseif (HH==4)
plot(mass,FuelEff)
xlabel('Normalised Data');
ylabel('Fuel Efficiency (km/kWh)');
title('');
hold on
end
end

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!