Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Using pushbutton to load file in GUI

Asked by Jared on 1 Nov 2011
Latest activity Commented on by Zhangxian on 19 Nov 2013

I am new to creating a GUI. I am using guide, and have a push button that opens a uigetfile dialog box using the code:

[filename1,filepath1]=uigetfile({'*.*','All Files'},...
  'Select Data File 1');

It seems to work. It opens, I select a file and hit ok, but there is no "rawdata1" in the matlab workspace. Where is this file stored?




No products are associated with this question.

3 Answers

Answer by Naz on 1 Nov 2011
Accepted answer

do this:

rawdata1=load([filepath1 filename1]);

GUI does not pass files to the workspace. You have to use the rawdata1 variable withing the function. You can make it semi-global by doing handles.rawdata1=load([filepath1 filename1]); and then access it the same way. If you leave the current function you must save changes to your handles.rawdata1 by typing this:

guidata(hObject, handles);

before you exit the function. If you want to copy the variable to the workspace, see my answer here:

1 Comment

Zhangxian on 19 Nov 2013

Great! It helps a lot

Answer by Fangjun Jiang on 1 Nov 2011

Your code is inside a GUI callback function so rawdata1 is in the function workspace, not the MATLAB base workspace.

To understand the difference, see

To load into the base workspace, you need to use evalin() or assignin()


Fangjun Jiang
Answer by Micah on 1 Nov 2011

GUIs (and functions) do not put variables into the 'seen' matlab workspace. They are in a separate space for that specific GUI (or function). So loading a variable in a GUI will not allow you to manipulate it in the workspace, and loading a variable in the workspace will not allow the GUI to use it. Also, if you have two GUIs, and load the variable 'rawdata' in the first, the second will not be able to use it, and you won't ever be able to 'see' it in the workspace.



Contact us