I would like to change the massflowrate when the statement is correct, could you help?
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Adam Street
le 14 Mar 2020
Commenté : Adam Street
le 14 Mar 2020
For some reason the massflowrate doesn't change itself whenever I enter the following, no errors or anything appear. Just got no clue how to fix this.
electricalsignal=5;
massflowrate=3;
if electricalsignal==0
disp("error")
else
temperature = 200*electricalsignal-400;
end
if temperature<74;
disp("opening valves")&& massflowrate == massflowrate-50;
elseif (74<=temperature) && (temperature>=78)
disp("closing valves")
elseif temperature>78
disp("closing valves") && massflowrate == massflowrate+50;
endif
1 commentaire
Guillaume
le 14 Mar 2020
I would strongly recommend that you go through the free matlab onramp to learn the basics of matlab.
I'm not entirely sure what you're trying to achieve with these lines:
disp("opening valves")&& massflowrate == massflowrate-50;
it's a completely made up syntax.
Réponse acceptée
Subhamoy Saha
le 14 Mar 2020
Modifié(e) : Subhamoy Saha
le 14 Mar 2020
The problem is with the line you are changing values of massflowrate. You are making it logical condition rather assigning it a new value. Please try the following
electricalsignal=5;
massflowrate=3;
if electricalsignal==0
disp("error")
else
temperature = 200*electricalsignal-400;
end
if temperature<74;
disp("opening valves"), massflowrate = massflowrate-50; % corrected
elseif (74<=temperature) && (temperature>=78)
disp("closing valves")
elseif temperature>78
disp("closing valves"), massflowrate = massflowrate+50; % corrected
end
5 commentaires
Subhamoy Saha
le 14 Mar 2020
Modifié(e) : Subhamoy Saha
le 14 Mar 2020
Dear Adam, the massflowrate is not changing beacause for electricalsignal=5 temperature=600 which satisfies your second elseif condition and doesnot change massflowrate (as there is not conditions in your code). Actually there is a problem in your second elseif condition. I think you want to imply
elseif (74<=temperature) && (temperature<=78)
Please correct this condition as per your need.
However, the solution I provided is working fine. Just change the electricalsignal value to something else like 2.1 or so. For its value 3 it is going to your second elseif condition.
Anyway, here is the full corrected code
electricalsignal=5;
massflowrate=3;
if electricalsignal==0
disp("error")
else
temperature = 200*electricalsignal-400;
end
if temperature<74;
disp("opening valves"), massflowrate = massflowrate-50; % corrected
elseif (74<=temperature) && (temperature<=78) %% corrected
disp("closing valves")
elseif temperature>78
disp("closing valves"), massflowrate = massflowrate+50; % corrected
end % corrected
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Numerical Integration and Differential Equations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!