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

7 ビュー (過去 30 日間)
Janos Bodi
Janos Bodi 2019 年 10 月 8 日
編集済み: Stephen23 2019 年 10 月 8 日
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)

採用された回答

Stephen23
Stephen23 2019 年 10 月 8 日
編集済み: Stephen23 2019 年 10 月 8 日
"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{:}];

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by