Only first for loop is being executed. What im i doing wrong?

The code is part of a file for calculating reverb time of a room under set conditions.
MF = input('Enter the measurement frequency required in Hz(Default =125Hz): ');
if isempty(MF)
MF = 125; %default value for MF if this is left blank, using an if statement
end
%adding the absorption coefficients of the materials in use
%into the code for each of the 6 frequencies
for MF = 125; %frequency at which the absorption coefficients below apply
a1 = 0.8; %absorption coefficient for carpet on foam
a2 = 0.013; %absorption coefficient for plaster on brick
a3 = 0.29; %absorption coefficient for plasterboard
a4 = 0.35; %absorption coefficient for glass
a5 = 0.28; %absorption coefficient for wood
end
for MF = 250; %frequency at which the absorption coefficients below apply
a1 = 0.24; %absorption coefficient for carpet on foam
a2 = 0.015; %absorption coefficient for plaster on brick
a3 = 0.10; %absorption coefficient for plaster on plasterboard
a4 = 0.25; %absorption coefficient for glass
a5 = 0.22; %absorption coefficient for wood
end
for MF = 500; %frequency at which the absorption coefficients below apply
a1 = 0.57; %absorption coefficient for carpet on foam
a2 = 0.02; %absorption coefficient for plaster on brick
a3 = 0.05; %absorption coefficient for plaster on plasterboard
a4 = 0.18; %absorption coefficient for glass
a5 = 0.17; %absorption coefficient for wood
end
for MF = 1000; %frequency at which the absorption coefficients below apply
a1 = 0.69; %absorption coefficient for carpet on foam
a2 = 0.03; %absorption coefficient for plaster on brick
a3 = 0.04; %absorption coefficient for plaster on plasterboard
a4 = 0.03; %absorption coefficient for glass
a5 = 0.09; %absorption coefficient for wood
end
for MF = 2000; %frequency at which the absorption coefficients below apply
a1 = 0.71; %absorption coefficient for carpet on foam
a2 = 0.04; %absorption coefficient for plaster on brick
a3 = 0.07; %absorption coefficient for plaster on plasterboard
a4 = 0.04; %absorption coefficient for glass
a5 = 0.10; %absorption coefficient for wood
end
for MF = 4000; %frequency at which the absorption coefficients below apply
a1 = 0.73; %absorption coefficient for carpet on foam
a2 = 0.05; %absorption coefficient for plaster on brick
a3 = 0.09; %absorption coefficient for plaster on plasterboard
a4 = 0.05; %absorption coefficient for glass
a5 = 0.11; %absorption coefficient for wood
end

 Réponse acceptée

James Tursa
James Tursa le 20 Mar 2017
Modifié(e) : James Tursa le 20 Mar 2017
It is a bit unclear why you are attempting to use for-loops here. From the looks of things, it appears that maybe you need to use if-tests instead. E.g.,
if MF == 125; %frequency at which the absorption coefficients below apply
a1 = 0.8; %absorption coefficient for carpet on foam
a2 = 0.013; %absorption coefficient for plaster on brick
a3 = 0.29; %absorption coefficient for plasterboard
a4 = 0.35; %absorption coefficient for glass
a5 = 0.28; %absorption coefficient for wood
end
if MF == 250; %frequency at which the absorption coefficients below apply
a1 = 0.24; %absorption coefficient for carpet on foam
a2 = 0.015; %absorption coefficient for plaster on brick
a3 = 0.10; %absorption coefficient for plaster on plasterboard
a4 = 0.25; %absorption coefficient for glass
a5 = 0.22; %absorption coefficient for wood
end
if MF == 500; %frequency at which the absorption coefficients below apply
a1 = 0.57; %absorption coefficient for carpet on foam
a2 = 0.02; %absorption coefficient for plaster on brick
a3 = 0.05; %absorption coefficient for plaster on plasterboard
a4 = 0.18; %absorption coefficient for glass
a5 = 0.17; %absorption coefficient for wood
end
if MF == 1000; %frequency at which the absorption coefficients below apply
a1 = 0.69; %absorption coefficient for carpet on foam
a2 = 0.03; %absorption coefficient for plaster on brick
a3 = 0.04; %absorption coefficient for plaster on plasterboard
a4 = 0.03; %absorption coefficient for glass
a5 = 0.09; %absorption coefficient for wood
end
if MF == 2000; %frequency at which the absorption coefficients below apply
a1 = 0.71; %absorption coefficient for carpet on foam
a2 = 0.04; %absorption coefficient for plaster on brick
a3 = 0.07; %absorption coefficient for plaster on plasterboard
a4 = 0.04; %absorption coefficient for glass
a5 = 0.10; %absorption coefficient for wood
end
if MF == 4000; %frequency at which the absorption coefficients below apply
a1 = 0.73; %absorption coefficient for carpet on foam
a2 = 0.05; %absorption coefficient for plaster on brick
a3 = 0.09; %absorption coefficient for plaster on plasterboard
a4 = 0.05; %absorption coefficient for glass
a5 = 0.11; %absorption coefficient for wood
end
The logic could be made simpler with if-elseif-else-end logic, or a switch statement. This would easily allow you to have some sort of error catch if the user did not input an acceptable value for MF. E.g.,
if MF == 125; %frequency at which the absorption coefficients below apply
etc
elseif MF == 250; %frequency at which the absorption coefficients below apply
etc
:
elseif MF == 4000; %frequency at which the absorption coefficients below apply
etc
else
error('Invalid MF');
end

Plus de réponses (1)

Edward Gomez
Edward Gomez le 20 Mar 2017
Thanks James, that fixed it. I was trying to use if-else if statements but this returned parse errors always and i got confused and decided to use for loops.
But now it works perfectly.
Thanks a lot
Ed

Catégories

En savoir plus sur Statics and Dynamics dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by