필터 지우기
필터 지우기

use .m file

조회 수: 6 (최근 30일)
Max Yaffe
Max Yaffe 2023년 4월 8일
답변: Walter Roberson 2023년 4월 8일
How do I use a .M file with two functions defined in the Command Window?

채택된 답변

Walter Roberson
Walter Roberson 2023년 4월 8일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by