Error in UIgetfile

Hi,
How to load multiple mat files into the workspace , I tried this but working only for single mat file.
[FileName,PathName] = uigetfile('*.mat','Select mat file','MultiSelect','on');
NAME = [PathName,FileName];
evalin('base',['load ' NAME]);

답변 (2개)

Walter Roberson
Walter Roberson 2012년 4월 28일

0 개 추천

uigetfile() returns a cell array of strings when MultiSelect is on.
It is not possible to request to load multiple files in a single load() statement. You will have to loop.
Loading a mat file into a workspace the way you are doing is not recommended, as the files might happen to contain variable names that interfere with something else you are doing.

댓글 수: 2

Karthik KJ
Karthik KJ 2012년 5월 19일
do you say to load it as guidata?
Walter Roberson
Walter Roberson 2012년 5월 20일
Use the function form of load() to return a structure that contains all the loaded variables as fields. If you must write the results into the base workspace for some reason, then write the entire structure as a unit.
Assume that the user is going to be malicious and deliberately ask to load a .mat file that has a variable name the same name as some important existing variable.

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

Jan
Jan 2012년 5월 19일

0 개 추천

[FileName, PathName] = uigetfile('*.mat','Select mat file','MultiSelect','on');
if ~isequal(FileName, 0)
FileName = cellstr(FileName); % Care for a single selection
for iFile = 1:numel(FileName)
evalin('base', ['load ', fullfile(PathName, FileName{iFile}]);
end
end
I do not like evalin, because it impedes debugging and poofing variables to another workspace slows down Matlab. The JIT acceleration cannot recognize the existence or type of a variable when they are injected from a subfunction using evalin. It would be better to forward the loaded data structs as outputs.

카테고리

도움말 센터File Exchange에서 App Building에 대해 자세히 알아보기

질문:

2012년 4월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by