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 个评论
Stephen23
2016-9-3
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!