In MATLAB, how can I run multiple .m files (M file) automatically?

In MATLAB , how can I automatically run 20 .m files (M file)?

+3
source share
2 answers

Make another M file and put in it all the names of the 20 existing M files.

If you want them to start at startup, put them startup.min the startup directory (see doc startup).

If they have systematic names, you can put the following in a loop:

[y1, y2, ...] = feval(function, x1, ..., xn)

where functionis the line you are developing in a loop.

Edit: if M files are scripts and not functions, it is safer for future versions:

eval(s)

where sis the name of the script.

+6

, , . MATLAB - . c:\work\myTwentyFiles, "runMyFiles.m",

function runMyFiles()
myDir = 'c:\work\myTwentyFiles';

d = dir([myDir filesep '*.m']);
for jj=1:numel(d)
    try
        toRun = fullfile(myDir, d(jj).name);
        fprintf('Running "%s"', toRun);
        run(toRun)
    catch E
        % Up to you!
    end
end

"-r", MATLAB :

matlab -r runMyFiles

- MATLAB ...

: -

d = {'myfun1','myfun2', 'myfun3'};

- - "toRun" -

toRun = fullfile(myDir, d{jj});
+4

Source: https://habr.com/ru/post/1733851/


All Articles