如果我这样写:
clc
clear
close all
format long
fprintf( 1, 'Starting...
' )
function results = do_thing()
results = 1;
end
results = do_thing()
并使用Octave运行它,它可以正常工作:
Starting...
results = 1
但是,如果我尝试使用Matlab 2017b运行它,则会抛出此错误:
Error: File: testfile.m Line: 13 Column: 1
Function definitions in a script must appear at the end of the file.
Move all statements after the "do_thing" function definition to before the first local function
definition.
然后,如果我按以下方式修复错误:
clc
clear
close all
format long
fprintf( 1, 'Starting...
' )
results = do_thing()
function results = do_thing()
results = 1;
end
它可以在Matlab上正常工作:
Starting...
results =
1
但是现在,它不再使用Octave:
Starting...
error: 'do_thing' undefined near line 8 column 11
error: called from
testfile at line 8 column 9
如何解决此问题而不必为函数do_thing()创建单独的专有文件?
此问题是否在某些较新版本的Matlab(2019a)中得到解决?