How to load in .m files in a sequence to Matlab?

10 vues (au cours des 30 derniers jours)
Janos Bodi
Janos Bodi le 8 Oct 2019
Modifié(e) : Stephen23 le 8 Oct 2019
I am trying to solve a problem where I have to use multiple .m files to extract information from them and modify it slightly. The problem is that I cannot load in all .m files at once as the variables would overwrite each other (all .m files conatin the same variables but at different time steps). Can anybody help me how to create a sequence specifically for .m files or which command could be used? (I tried load and importdata commands, did not seem to work)

Réponse acceptée

Stephen23
Stephen23 le 8 Oct 2019
Modifié(e) : Stephen23 le 8 Oct 2019
"The problem is that I cannot load in all .m files at once..."
Your question is confusing: .m files contain code (and in general they are not loaded as data), whereas .mat files contain data variables (which can be loaded into MATLAB memory). M-files can be scripts or functons or classes, which can be run/called as appropriate. But usually it does not make much sense to load them.
I will assume that you actually have multiple .mat files, in which case you can easily prevent variables being overwritten in a loop by loading the .mat files into an output variable (which is a scalar structure)
S = load(...);
If all of the .mat files contain exactly the same variables, then that scalar structure can easily be joined into one non-scalar structure, which makes access all of the data easy:
N = number of files
A = cell(1,N);
for k = 1:N
A{k} = load(...);
end
A = [A{:}];

Plus de réponses (0)

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by