Attempt to execute SCRIPT <filename> as a function

7 ビュー (過去 30 日間)
Ivy Chan
Ivy Chan 2015 年 1 月 29 日
コメント済み: Walter Roberson 2020 年 8 月 14 日
Hi all, I am a new user of Matlab. Im learning how to debug a .m file called "test.m". I was asked to copy one backup, I made the name "test_debug.m". When I run the test_debug.m file, there is a error msg,
Attempt to execute SCRIPT test as a function: D:\ProgramFiles\Reference_src\test.m
test.m is not in path. But it could still successful run. It has called several functions inside the script. What should I add into/make changes for test_debug.m?
Thank you!
  3 件のコメント
Image Analyst
Image Analyst 2020 年 8 月 14 日
Chances are you named your m-file after a built-in function. Attach your m-file with the paper clip icon in a new question.
Walter Roberson
Walter Roberson 2020 年 8 月 14 日
You would get that error message if you had accidentally corrupted newplot.m such as accidentally typing in a few characters before the 'function' line.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2015 年 1 月 29 日
Does the first line of test_debug say either
function test()
or
function test_debug()
or does it not have a function line at all?
It should say function test_debug - if it does not but has included other functions declared within the same m-file, then you will get that message since you can't have a script and a function in the same m-file. It has to be just a single script (meaning no function line) or it has to be one or more functions that are declared in it. ?
  2 件のコメント
Image Analyst
Image Analyst 2015 年 2 月 3 日
Ivy's "Answer" moved here because it's not an Answer to her original question but a reply to me:
The first line of test_debug does not say neither these two. Instead, it first load a .dat file. Then it uses "size" to save the data into variables.
close all;
clc;
clear all;
tic;
load data_offline;
[y x c n]=size(raw_data);
It has to be more functions that are declared in it. So is test_debug a script? It has some functions but I can still run it and make figure.
Thanks!
Image Analyst
Image Analyst 2015 年 2 月 3 日
Whatever the name of your m-file is, that name has to be preceded by the word "function" as the first line in the file (or at least the first non-comment line). So if your m-file is called test.m you need to have this as line #1:
function test()
If your m-file is called test_debug.m you need to have this as line #1:
function test_debug()

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by