Functions and Sub Functions
조회 수: 5 (최근 30일)
이전 댓글 표시
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
dpb
2019년 4월 27일
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.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!