script to call functions

i would like to script a main.m that will offer choices of functions to run, 7 in all, where each function correlates to a number, 1:7.

 채택된 답변

Paulo Silva
Paulo Silva 2011년 2월 22일

0 개 추천

function main
s=input('insert the function number: ')
switch s
case 1
fun1
case 2
fun2
case 3
fun3
case 4
fun4
case 5
fun5
case 6
fun6
case 7
fun7
otherwise
disp('Error, you must insert number from 1 to 7')
end

댓글 수: 1

Paulo Silva
Paulo Silva 2011년 2월 22일
If you really want you can add more info before getting the user selection with the disp function, example
disp('Select 1 for the fun1 that does a+b')
disp('Select 2 for the fun2 that does a-b')

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 2월 22일

0 개 추천

funs = {@fun1, @fun2, @fun3, @fun4, @fun5, @fun6, @fun7};
s = input('insert the function number: ');
funs{s}()

카테고리

도움말 센터File Exchange에서 Just for fun에 대해 자세히 알아보기

질문:

2011년 2월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by