Why do I get the error message 'Attempt to execute SCRIPT as a function' ?

조회 수: 264 (최근 30일)
Why do I get the following error message:
Attempt to execute SCRIPT as a function.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2012년 12월 12일
Explanation:
You are attempting to call a script file as though it were a function file by passing arguments to it.
Common causes:
1. You have created a script MATLAB file with the same name as a function on the MATLAB path but higher on the path than that function;
2. You are attempting to index into an array that does not exist when a script file with that name exists.
Solution:
Execute
>> which -all filename
for the file specified in the error message. Verify that the file you expect to execute is being used instead of any other file with the same name. If it is not, rename or delete the files higher on the MATLAB path than the file you expect to use, or reorder the directories on your MATLAB path to place the version of the file you want to use higher than any other version.
The attached example ("AttemptExecuteScriptAsFunction.m" and "TestScriptAsFunction.m") demonstrates this error. Save these files in your current folder and execute at the MATLAB prompt:
>> AttemptExecuteScriptAsFunction
  댓글 수: 1
Steven Lord
Steven Lord 2020년 2월 6일
Your CW2.m is a script not a function. See this page for a short description of how they look and act differently.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

태그

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by