octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Functions in scripts: Matlab evolves


From: Mike Miller
Subject: Re: Functions in scripts: Matlab evolves
Date: Tue, 24 Jan 2017 10:25:07 -0800
User-agent: NeoMutt/20161126 (1.7.1)

On Tue, Jan 24, 2017 at 15:56:17 +0100, Julien Bect wrote:
> Hi all,
> 
> I just learned that functions definitions are now allowed in Matlab scripts
> (>= R2016b).
> 
> But the functions definitions must be at the end of the script.
> 
> https://fr.mathworks.com/help/matlab/matlab_prog/create-functions-in-files.html
> 
> So, the following script works in Octave but fails in Matlab:
> 
> %%%%%%%%%%%%%%%%%
> 
> x = 1;
> 
> function y = f(x)
> y = 2 * x;
> end
> 
> z = f(x)
> 
> %%%%%%%%%%%%%%%%%
> 
> and this one works in Matlab (>= R016b) but fails in Octave:
> 
> %%%%%%%%%%%%%%%%%
> 
> x = 1;
> 
> z = f(x)
> 
> function y = f(x)
> y = 2 * x;
> end
> 
> %%%%%%%%%%%%%%%%%

Does the function f() exist in Matlab's workspace after the script
completes? If it is locally scoped to the execution of the script only,
that is yet another difference with Octave.

-- 
mike



reply via email to

[Prev in Thread] Current Thread [Next in Thread]