Azzera filtri
Azzera filtri

use .m file

6 visualizzazioni (ultimi 30 giorni)
Max Yaffe
Max Yaffe il 8 Apr 2023
Risposto: Walter Roberson il 8 Apr 2023
How do I use a .M file with two functions defined in the Command Window?

Risposta accettata

Walter Roberson
Walter Roberson il 8 Apr 2023
If a .m file is a script file (first executable word is not function or classdef ) then you cannot directly call any functions defined in the script file from outside of the .m file.
If a .m file is a function file (first executable word is function) then you can only directly call the first function in the file, and the name you invoke it by must be the same as the name of the file (the actual name given in the function line will be ignored in this case.)
If a .m file is a class definition, then you can only directly call the constructor and public static methods, unless you are passing in a member of the class in which case you can call public methods.
If you need to be able to call additional functions inside a script file or inside a function file, then the only way to do so if you have somehow been provided with a handle to the function.
H = get_impl();
H{2}()
setter invoked
function H = get_impl()
H = {@my_getter, @my_setter};
end
function my_getter()
disp('getter invoked');
end
function my_setter()
disp('setter invoked')
end

Più risposte (0)

Tag

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by