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 comentario

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

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Productos

Etiquetas

Preguntada:

el 3 de Sept. de 2016

Comentada:

el 3 de Sept. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by