Why am I getting this error?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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
답변 (1개)
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!