Need help with my function (Basic Question)

Hi, I need help with my function using if statements. When I try it with random pH its giving me incorect messages. Im not sure how to fix it. Heres what i have so far:
message = "acidic";
if 0<= pH, pH<7
end
message = "neutral";
if pH==7
end
message = "basic";
if 7<pH, pH>=14
end
message = "Not valid pH";
if 0>pH, pH<14
ph=0;
end

 Respuesta aceptada

Jacob Gonzalez
Jacob Gonzalez el 27 de Sept. de 2018
Step1: I think it would be better to replace your commas with && like so:
if 0 <= pH && ph < 7
% code
end
To make code function, we would then place the messages within the if statements like so:
if 0 <= pH && ph < 7
message = 'acidic';
end
Lastly, it is better form to you if-elseif-else in this situation:
if 0<= pH && pH < 7
message = "acidic";
elseif pH == 7
message = "neutral";
elseif pH > 7 && pH <= 14
message = "basic";
else
message = "Not valid pH";
pH=0;
end
Hope this helps you understand.

1 comentario

Daud Muhammad
Daud Muhammad el 29 de Sept. de 2018
A quick question why do you put ph=0; at the end? is this neccessary?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 27 de Sept. de 2018

Comentada:

el 29 de Sept. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by