필터 지우기
필터 지우기

Errors in Menu program

조회 수: 2 (최근 30일)
Oliver
Oliver 2011년 12월 22일
Hi all,
I'm a newbie to Matlab and wrote a program using menu as follows:
*eapplication.m*
choice = eoption;
while choice ~= 4
switch choice
case 1
explaine;
case 2
limite;
case 3
x = input('Please enter a value for x: ');
expfn(x);
end
choice = eoption;
end
*eoption.m*
choice = menu('Choose an e option', 'Explanation', 'Limit', ... 'Exponential function', 'Exit Program');
while choice == 0
disp('Error - please choose one option.')
choice = menu('Choose an e option', 'Explanation', 'Limit', ... 'Exponential function', 'Exit Program'); end
*It gave me an error: ??? Attempt to execute SCRIPT eoption as a function: C:\Documents and Settings\Olive\My Documents\MATLAB\eoption.m
Error in ==> eapplication at 1 choice = eoption;*
Could you please shed some lights?
Thanks heaps.
Oliver.

채택된 답변

Matt Tearle
Matt Tearle 2011년 12월 22일
Pretty much what it says. The line choice = eoption; implies that eoption is a function call (because it is asking for an output, to be assigned to choice). But eoption is a script, not a function.
The difference is in how variables are managed. Scripts work with the base MATLAB workspace. Functions use local workspaces, so variables are local. So your options are:
  1. Turn eoption into a function by adding the line function choice = eoption at the beginning.
  2. Leave eoption as a script and inherit choice from the base workspace. Hence, change the line choice = eoption; (in eapplication) to just eoption;
  댓글 수: 2
Oliver
Oliver 2011년 12월 22일
Thank you so much Matt. You're wonderful. Can you recommend good books for me? I've got Matlab: a practical introduction to programming and problem solving and Matlab programming for Engineers. Both have errors.
Matt Tearle
Matt Tearle 2011년 12월 22일
There are a lot of books out there, as well as other resources. Are you in academia or industry? And you're in engineering (or did you just happen to have an engineering MATLAB book)?
http://www.mathworks.com/support/books/index_by_categorytitle.html?category=17&sortby=title

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

추가 답변 (1개)

Jose Jeremias Caballero
Jose Jeremias Caballero 2011년 12월 22일
Hello
clear all
clc
choice = menu('Choose a opcion','explaine','limite','expfun','exit of menu');
switch choice
case 1
explaine='matlab';
display(explaine);
case 2
syms x
limit((x-2)/(x^2-4),2)
case 3
x = input('Please enter a value for x: ');
expfn=inline('sin(x)+5');
expfn(x)
otherwise
display('thanks');
end

카테고리

Help CenterFile Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기

태그

아직 태그를 입력하지 않았습니다.

Community Treasure Hunt

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

Start Hunting!

Translated by