loading multiple .mat files from current directory

Hi,
Is there a way to load all the .mat files together into the base workspace?
files = dir('*.mat') gives a structure having details of the .mat files in the directory. But with load files(1).name (may be using a loop), I am not able to load a .mat file from the current folder to base workspace.
Any help is appreciated. Vijay

 채택된 답변

Walter Roberson
Walter Roberson 2012년 8월 14일
evalin('base', ['load ', files(K).name])
Warning: using this method is prone to clobbering variables in the base workspace, as it does not validate the contents of the .mat file before loading.

댓글 수: 5

Vijay
Vijay 2012년 8월 14일
편집: Walter Roberson 2018년 2월 1일
Thank you very much. I just want to load the files. I am using them in a function. Just now, I have found out similar solution as follows,
files = dir('*.mat');
for i = 1:numel(files)
load(files(i).name);
end
Hi, can u explain more clearly about what is 'load(files(i).name)' mean? can u give an example? thanks a lot !
The output of dir() is a struct (data structure) array with a number of fields, including the important field name . The name of the first file returned is available through files(1).name and the name of the second file is available through files(2).name and so on. These are all character vectors. You can pass load() a character vector to tell it which file to load.
can you please tell name is a key word or what
dir() returns a struct array. In current releases, that struct contains fields named
bytes
date
datenum
folder
isfolder
name
In terms of the MATLAB language, these are not considered keywords: they are just what the struct fields are named.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Workspace Variables and MAT Files에 대해 자세히 알아보기

질문:

2012년 8월 14일

댓글:

2018년 9월 25일

Community Treasure Hunt

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

Start Hunting!

Translated by