Why am I getting this error?

2 ビュー (過去 30 日間)
Muazma Ali
Muazma Ali 2022 年 3 月 5 日
コメント済み: Muazma Ali 2022 年 3 月 5 日
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 件のコメント
Image Analyst
Image Analyst 2022 年 3 月 5 日
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 2022 年 3 月 5 日
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..

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2022 年 3 月 5 日
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.
  1 件のコメント
Muazma Ali
Muazma Ali 2022 年 3 月 5 日
Thanks a lot ! :)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by