can't load file.mat into listbox?
Show older comments
Hallo, i've the following code and the problem with it. I load the file.mat into the workspace with a command 'uiimport', but after that there is nothing saved in the variable 'vars'. Is there any other solution to load file.mat into the listbox, so that i can after loading operate the variables from file.mat in the listbox? Here is my code:
function fileload
uiimport;
vars = evalin('base','who');
set(handles.listbox1,'String',vars);
Thanks
Maria
Answers (3)
Titus Edelhofer
on 19 Jan 2012
Hi,
whos might read directly from file, i.e.,
vars = whos('-file', 'file.mat');
set(handles.listbox1, 'String', {vars.name});
Titus
Walter Roberson
on 19 Jan 2012
1 vote
uiimport imports in to the current workspace, not in to the global workspace. If there are local variables with the same name as what it is importing, the local variables will be overwritten. It is not recommended for this situation.
I suggest you use uigetfile() to allow the user to pick the file, and use load() assigning the output to a variable. fieldnames() applied to the variable will tell you the names of the variables that were in the .mat file, and you can save the content of the .mat file for later use using any of the techniques described in http://matlab.wikia.com/wiki/FAQ#How_can_I_share_data_between_callback_functions_in_my_GUI.3F
Maria
on 19 Jan 2012
0 votes
1 Comment
Titus Edelhofer
on 19 Jan 2012
Hi Maria,
when you pick the variable, the listbox1_Callback is executed. You should load the variable
val = get(hObject, 'value');
str = get(hObject, 'string');
load('file.mat', str{val});
Titus
Categories
Find more on Startup and Shutdown in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!