How to load a mat.file from a selected folder to workspace from a GUI and MAINTAIN the original Data Type

2 views (last 30 days)
Hello,
i found this code snippet for loading a mat.file to the workspace. It works fine! The only problem is, that the file is a STRUCT!!!
When i open the file manually from the matlab surface, it is a Matrix named 'x'. Thats how i would like it to be here tooo! dont want to have a struct instead.
startingFolder = 'C:\Program Files\MATLAB'
% Get the name of the mat file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.mat')
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a mat file')
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName)
storedStructure = load(fullFileName) % only available in the GUI so far, not in the workspace
assignin('base', 'storedStructure', storedStructure); % now transported to the workspace, accessable by storedStructure.x
Can anybody help me with that plz:)
thank you very much!
Best regards, John

Accepted Answer

Walter Roberson
Walter Roberson on 9 Sep 2015
assignin('base', 'x', storedStructure.x); % now transported to the workspace
However, this is not recommended!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!