Batch processing of .m files
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi!
I have a set of .m files with file names in sequence (e.g., 1.m, 2.m,..., 100.m). Each file is having a matrix named X with different values.
Within a common .m file (say BatchPro.m) I wish to call files 1.m, 2.m, .... one by one using a for loop to get the data stored on it (matrix X), so that I can process individual values of the matrix X. How to do this batch process?
I m looking for something like:
S = [];
FileList = dir('*.m'); N = size(FileList,1);
for k = 1:N
FileList(k); %To call 1.m, 2.m, ...
S(k) = mean(X); % X is a row vector in stored in 1.m, 2.m, ...
end
0 comentarios
Respuestas (2)
Matt J
el 23 de Oct. de 2012
You can use EVAL to call the different mfiles, but you should correct whatever got you into the awkward situation of needing to do this.
0 comentarios
Jan
el 23 de Oct. de 2012
You cannot start a function or script, when its file is called "1.m". How would the call look like?
1
?! M-file names must be valid Matlab symbols: Starting with a letter, only letters, digits and the underscore, less than 64 characters.
Therefore this will work:
FileList = dir('*.m');
N = size(FileList,1);
S = zeros(1, N); % Pre-allocate!!!
for k = 1:N
File = FileList(k).name;
copyfile(File, 'myTempScript.m');
clear('myTempScript');
run('myTempScript'); % Assuming that the files are scripts
S(k) = mean(X);
delete('myTempScript.m');
end
0 comentarios
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!