The variable already defined ,but in the design apps it cannot recognized the variable.
이전 댓글 표시
Unrecognized function or variable 'A'.
Error in Tariff (line 21)
F6 = A+B+C;
function Bill = Tariff(Energy)
if Energy <=200
A = Energy*0.218;
B=0; C=0; D=0; E=0; P=0.4; EST= 0;
elseif Energy <=300
A = 43.6;
B = (Energy-200)*0.334;
C=0; D=0; E=0; P=0.15; EST= 0;
elseif Energy <=600
A = 43.6; B = 33.4;
C = (Energy-300)*0.516;
D=0; E=0; P=0.1; EST= 0;
elseif Energy <= 900
A = 43.6; B = 33.4; C = 154.8;
D = (Energy-600)*0.546;
E=0; P=0.05; EST= Energy-600;
elseif Energy > 900
A = 43.6; B = 33.4; C = 154.8; D = 327.6;
E = (Energy-900)*0.571; P=0; EST= Energy-600;
end
F6 = A+B+C;
ST = D+E;
Total = F6+ST;
ICPT = Energy*0.02;
ICPTST = EST*0.02;
Pemulih = round((Total-ICPT)*P,2);
PemulihST = round((ST-ICPTST)*P,2);
STtotal = round(ST-ICPTST-PemulihST,2);
Tax = round((STtotal)*0.06,2);
KWTBB = round((Total-Pemulih)*0.016,2);
Bill = round(Total-ICPT-Pemulih+Tax+KWTBB,1);
댓글 수: 2
Stephen23
2021년 11월 2일
"The variable already defined"
Nope, consider what your code does if Energy = [0,1000]
It looks like you are making the common beginner mistake of using IF/ELSEIF/ELSE when you should be using indexing.
Lee Yit Tung
2021년 11월 3일
채택된 답변
추가 답변 (1개)
Jan
2021년 11월 2일
Why do you assume, that "the variable A is already defined", if Matlab displays clearly, that it is not?
What is your input Energy? If it is an array, the expression
if Energy <=200
is interpreted as:
if all(Energy(:) <= 200)
When none of the conditions is met for all elements of Energy, the variable A is not defined.
Use the debugger to examine what's going on: Set a breakpoint in the first line and step through your code line by line. You will see, that no code is executed, wich defines A.
댓글 수: 3
Lee Yit Tung
2021년 11월 3일
Stephen23
2021년 11월 3일
@Lee Yit Tung: then set DBSTOP IF ERROR and save the value of ENERGY in a mat file and upload it here by clicking on the paperclip button. Then we can help you to find out why your code does not work.
Lee Yit Tung
2021년 11월 3일
카테고리
도움말 센터 및 File Exchange에서 Instrument Control Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!