0
function [x,y]=func1(x,y)
x = input('Enter how many tickets you would like: ');
y = input('Enter what level you would like to sit in: ');
end
功能2:
function [z] = func2(x,y)
switch l
case y==1
z = 500*x;
case y==2
z = 350*x;
case y==3
z = 200*x;
end
功能3:
function [x,y,z]=func3(x,y,z)
[x,y]=func1(x,y);
z=func2(x,y);
fprintf('It will cost $%.2f for %d tickets in level %d.','z','x','y');
end
我想在連續這三個函數調用(這是我如何嘗試去做的):
func1(x,y)
func2(x,y)
func3(x,y,z)
我想僅三條線被印刷(除欲被印刷,而不是X,Y,Z中的實際計算):
Enter how many tickets you would like:
Enter what level you would like to sit in:
It will cost $z for x tickets in level y.
第一這兩行出來細,但第三個打印隨機數代替x,y,z。我究竟做錯了什麼?
閱讀有關'switch - case'構造手冊 - http://www.mathworks.com/help/matlab/ref/switch.html'case y == 1'不正確,因爲case值應該等於'switch'語句中使用的變量的值。你在那裏沒有變量'l'。 – Cheery 2014-10-29 22:23:02