Opening/loading multiple mat files?

I know how to open multiple mat files, using
filename = uigetfile('*.*', 'All Files (*.*)','MultiSelect','on');
But this returns a cell array with the file names that I selected. How would I access these files names for the information stored within them?

回答(2 个)

load(filename{1}); %to load the contents of the first file
load(filename{2}); %to load the contents of the second file
...
%and so on

4 个评论

Since the number of files is variable, would something like this work a little better?
for n=1:length(filename)
load(filename{n});
end
Yes, a for-loop can work well here. I was simply demonstrating the syntax of calling the load function.
One thing to be careful of, however, is if files have similar variables. For instance, if two files have the variable x, then after running the for-loop, you will only have the value(s) for x of the last file that was loaded. To combat this issue, consider using
data{n} = load(filename{n});
or something similar to store the data.
Perfect, I actually was trying to figure out how to combat that, thanks!.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by