フィルターのクリア

How to retrieve handles (data) of MATLAB GUI from saved .fig file?

2 ビュー (過去 30 日間)
Dominik Mattioli
Dominik Mattioli 2018 年 4 月 3 日
コメント済み: Walter Roberson 2018 年 4 月 3 日
I need to retrieve about 100 saved GUI's (templated from Guide), so I'd rather not open each file and manually load the data into the workspace. Is there an automated way to load these files and grab the handles.output data?
Folder = uigetdir(''); % Get my folder.
currentDir = dir(Folder);
collectiveData = cell(length(currentDir)-4,1);
for idx = 4:length(currentDir) % Loop through all saved files, skipping "." and ".." and ".DS_Store".
load(currentDir(idx).name); % Load saved file
% load handles of figure or something?
% collectiveData{idx-4} = handles.output; % Ideally do this?
end
I imagine that it would look like that but I can't figure out how to get my gui into the workspace programmatically :(

採用された回答

Walter Roberson
Walter Roberson 2018 年 4 月 3 日
You can openfig() the file which will return the handle to the figure, and you can then guidata() that to retrieve the handles structure.
However in my experience, handles.output typically has nothing useful until the gui has been executed and some step deliberately puts information there.
  2 件のコメント
Dominik Mattioli
Dominik Mattioli 2018 年 4 月 3 日
I ended up doing this, although opening 100+ figures is a little taxing. Thank you for the answer!
Walter Roberson
Walter Roberson 2018 年 4 月 3 日
Folder = uigetdir(''); % Get my folder.
currentDir = dir( Folder);
currentDir([currentDir.isdir]) = []; %., .. and any other folders
currentdir(ismember({currentDir.name}, {'.DS_Store'})) = [];
filenames = fullfile(currentDir, {currentDir.name});
nfile = length(filenames);
collectiveData = cell(nfile,1);
for idx = 1:nfile
try
fig = openfig(filenames{idx});
figh = guidata(fig);
collectiveData{idx} = figh.output;
delete(figh);
catch
if isgraphics(figh); delete(figh); end
end
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by