Borrar filtros
Borrar filtros

Varying multiple model inputs in MATLAB loop

2 visualizaciones (últimos 30 días)
Mark Kelly
Mark Kelly el 4 de Mzo. de 2014
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

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by