

Note that technically the functions here in Octave are not "local functions", but "command-line functions". Move all statements after the "foo" function definition to before the first local function definition.
Matlab 2019a compatibility code#
So just use functions if you want code that will work on both Matlab and Octave.Įxamples: Functions at end disp('Hello world')Įrror: 'foo' undefined near line 2 column 1Įrror: File: myscript.m Line: 7 Column: 1 So you can use local functions in scripts on both applications, but you can't write a script that will work on both. For 2019a and higher, these functions are built into MATLAB so. The ThingSpeak Support Toolbox lets you use MATLAB (R2014b through R2018b) to read data from ThingSpeak and write data to ThingSpeak. But Matlab requires that local functions in scripts all be defined at the end of the file. ThingSpeak is a web service hosted by MathWorks that lets you collect, analyze and act on sensor data, and develop Internet of Things applications. Octave requires that local functions in scripts be defined before their use. Octave's implementation of local functions in scripts is different from Matlab's. Why? Because, if you want intercompatible code, you should rely on the canonical form and good programming practices instead of littering your scripts with dynamic functions, which is what you should be doing anyway. Matlab was incompatible with advanced octave functionality, and now that it has introduced its own implementation of this functionality, it is still incompatible. (rant: this may be a coincidence and an earnest design decision, but I do note that it also happens to go against prior matlab conventions regarding nested functions, which were allowed to be defined anywhere within their enclosing scope).
Matlab 2019a compatibility how to#
How to fix it without having to create a separate and exclusive file for the function do_thing()? This problem was explained on this question: Run octave script file containing a function definition It works correctly on Matlab: Starting.īut now, it stopped working with Octave: Starting.Įrror: 'do_thing' undefined near line 8 column 11 Move all statements after the "do_thing" function definition to before the first local function And run it with Octave, it works correctly: Starting.īut if I try to run it with Matlab 2017b, it throws this error: Error: File: testfile.m Line: 13 Column: 1įunction definitions in a script must appear at the end of the file.
