Why am I getting this error?

2 visualizaciones (últimos 30 días)
Muazma Ali
Muazma Ali el 5 de Mzo. de 2022
Comentada: Muazma Ali el 5 de Mzo. de 2022
I dont understand why I am getting the same error again, 'undefined function molaritet_NH4Cl ' I have given value to molaritet_NH4Cl
best_salt_1 and best_salt_2 are my inputs where they can have values: KCl, NH4Cl or ZnBr2.
maks_vektprosent are numbers lik 30 , 40 and 50
  2 comentarios
Image Analyst
Image Analyst el 5 de Mzo. de 2022
You aren't just clicking the green run triangle without ever assigning any of the inputs are you?
Please show the function where you called this function and assigned best_salt_1,best_salt_2,maks_vektprosent_lost_KCl ,maks_vektprosent_lost_NH4Cl ,maks_vektprosent_lost_zinkbromid
Muazma Ali
Muazma Ali el 5 de Mzo. de 2022
I ran this function as both calling it from another function and as from the command line where I just assigned best_salt_1 ="ZnBr2" and best_salt_2="NH4Cl" and with different values for maks_vektprosent but I got the same error..

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 5 de Mzo. de 2022
Your code assigns to molaritet_NH4Cl if best_salt_1 or best_salt_2 are exactly 'NH4Cl ' with a trailing space
if strcmpi(best_salt_1,' KCl')|strcmpi(best_salt_2,'KCl')
if strcmpi(best_salt_1,' NH4Cl')|strcmpi(best_salt_2,'NH4Cl')
samlet_ionic_strength=0.5*(molaritet_NH4Cl*1^(2) + molaritet_NH4Cl*(-1)^2 + molaritet_KCl*1^(2) + molaritet_KCl*(-1)^2);
That code uses the value of molaritet_NH4Cl if best_salt_1 is (case insensitive) ' NH4Cl' with a leading space or if best_salt_2 is (case insensitive) 'NH4Cl' with no spaces
The strcmpi() tests you coded will not match if best_salt_1 or best_salt_2 are 'NH4Cl ' with a trailing space as coded in your switch(), and the switch() statements will not match if best_salt_1 or best_salt_2 are ' NH4Cl' with a leading space or 'NH4Cl' with no space or are (for example) 'NH4CL ' (trailing space but not a case-sensitive match for 'NH4Cl ' that you have coded in your switch()
Spaces and case sensitivity matter.

Categorías

Más información sobre Operators and Elementary Operations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by