Clear Filters
Clear Filters

Calling Functions in a script

121 views (last 30 days)
Jonathan
Jonathan on 27 Oct 2014
Edited: Stalin Samuel on 27 Oct 2014
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)

Accepted Answer

Stalin Samuel
Stalin Samuel on 27 Oct 2014
Edited: Stalin Samuel on 27 Oct 2014

More Answers (0)

Categories

Find more on Language Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!