Functions and Sub Functions

6 views (last 30 days)
Flyers28
Flyers28 on 26 Apr 2019
Commented: Flyers28 on 27 Apr 2019
Need a little help as I am complete Matlab novice. I need to write a program consisting of 2 functions and a main function that calls the other 2 functions. For a little background, this will calculate gear ratios and max speed at each gear for the new adjusted gear ratio. My first Function (GetData) will collect info from the user using a Gui which asks 7 different questions. In that same function my output arguments are used to calculate the new and stock gear ratios and the tire circumference from gathered data.
My 2nd function will use the data gathered from the GetData function and make all the calculations using the outputs from the GetData function (stockGr, newGr, Tire). This data will be applied to several other calculations in order to determine max speed at each gear.
The main function will call both functions and plot a graph.
My troubles are I have no idea how to take the outputs from GetData, call that function in my Calc function and use the output arguments in the necessary calculations. I know this is probably a terrible way to program but I just need to get it done and meet the requirements. Just looking for some guidance here. I think I am also hung up on what should be my input and output arguments in both the main function and the calling function.
Thanks
  4 Comments
dpb
dpb on 27 Apr 2019
No, James' code could just as easily be three separate m-files.
The GetData function doesn't have any input arguments only outputs (altho one alternate way to do user input would be to let the user edit a text file that is read rather than enter each variable manually -- in that case, it would make sense to pass the file name as an argument.
It could get awfully old quickly to have to set all seven input variables every time...might want to think about whether most of those seven have default values or other ways to minimize the amount of absolutely necessary user interaction.
Flyers28
Flyers28 on 27 Apr 2019
Thanks guys, really appreciate the help. I think I got it to work. Next up is just learning a few more things on generating a plot exaclty how I want it. But you guys helped me with my biggest hurdle and for that I thank you again.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!