필터 지우기
필터 지우기

Calling Functions in a script

조회 수: 119 (최근 30일)
Jonathan
Jonathan 2014년 10월 27일
편집: Stalin Samuel 2014년 10월 27일
Sorry if this was already answered or its a stupid question but i am BRAND NEW to matlab and programming in general and am working out of a matlab text book that in general i find confusing already.
I was trying to create 3 different functions for an assignment and then run them with a separate script. As i understand functions they are each individual .m files so i created those three as needed:
FuncAsk is intended to ask for an input Z and W (where Z = number of tickets purchased and W = preferred seating of the tickets)
FuncCalc is intended to do different calculations with those variables Z and W depending on the value of W by using the switch command. (Because ticket prices change with seating positions) and i want it to output variable y for cost of tickets
FuncTell is intended to just display a sentence stating basically "Z tickets in seating level W will cost C dollars"
the thing i'm confused about is when i make a script to run each function that i called script2 i run into a lot of problems like "not enough input arguments" or undefined variables etc. I guess the main point is how do i connect each function together into a fluid script where the output of the first function is used as the input of the next and so on. Any help on how to do this or information on funtions in general will be appreciated.
the code for each function is below:
______________________
function FuncAsk
Z=input('Enter how many World Series tickets you would like: ')
W= input(' Enter what level you would like to sit in: ')
______________________
function FuncCalc
if W == 1
y = 500*Z
else
switch W
case 2
y = 350*Z
case 3
y= 200*Z
end
end
_______
function FuncTell
fprintf('It will cost %d for %d tickets in level %d', y,Z,X)

채택된 답변

Stalin Samuel
Stalin Samuel 2014년 10월 27일
편집: Stalin Samuel 2014년 10월 27일

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Language Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by