Use a Script file as the input to a function

Hello, I am looking to make a function file that accepts any .m script file as an input.
Here is an example of the code I am trying fix to do this. I want the input to be the file X.m
function Untitled( X.m )
% find the correct directory and file
io_contents = ...
fullfile('New Folder', 'X.m');
% read the file
filetext = fileread(io_contents);
end
I am relatively new to using MATLAB in this fashion. Any help would be appreciated!

1 个评论

It is not clear what you intend to do with this input, since it does not appear anywhere in the body of your function.
If you actually just want to be able to select the name of the fucntion via an input, then do this:
function Untitled(name)
io_file = fullfile('New Folder',name);
filetext = fileread(io_file);
end

请先登录,再进行评论。

回答(0 个)

类别

帮助中心File Exchange 中查找有关 File Operations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by