can't load file.mat into listbox?

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)

Hi,
whos might read directly from file, i.e.,
vars = whos('-file', 'file.mat');
set(handles.listbox1, 'String', {vars.name});
Titus
Walter Roberson
Walter Roberson on 19 Jan 2012
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
Maria on 19 Jan 2012
Hallo,
'whos' makes it good. But now i choose the variables from the listbox and, according to the fact that there is nothing in workspace, matlab gives the error:
Undefined function or variable 'KnopfMes1_1'.
'KnopfMes1_1' is the first name of an array in file.mat
Thanks Maria

1 Comment

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

Sign in to comment.

Categories

Asked:

on 19 Jan 2012

Community Treasure Hunt

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

Start Hunting!