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

Thread Subject:
Workspace variable to GUI

Subject: Workspace variable to GUI

From: George Haralam

Date: 24 Aug, 2010 00:49:04

Message: 1 of 5

Hello,

I am trying to create a GUI where I load in a .mat file (preferably from the GUI but at the moment I load it manually from the directory).

and inside the .mat file contains a 1x1 struct with other variables.

I am trying to plot the variables inside the struct inside my GUI.

I have right now :

function plotdata2_Callback(hObject, eventdata, handles)
axes(handles.axes2)
scatter(C1.struct.x,C1.struct.gsy)
title('Monte Carlo Demo');
xlabel('X data');
ylabel('Y data');
guidata(hObject, handles);

but even though the struct is loaded in the workspace, the error

??? Undefined variable "C1" or class "C1.struct.x".

comes up.

Anyone have some input.

Thanks in advanced-

George

Subject: Workspace variable to GUI

From: per isakson

Date: 24 Aug, 2010 01:25:05

Message: 2 of 5

"George Haralam" <justajawn@gmail.com> wrote in message <i4v4u0$jhp$1@fred.mathworks.com>...
> Hello,
>
> I am trying to create a GUI where I load in a .mat file (preferably from the GUI but at the moment I load it manually from the directory).
>
> and inside the .mat file contains a 1x1 struct with other variables.
>
> I am trying to plot the variables inside the struct inside my GUI.
>
> I have right now :
>
> function plotdata2_Callback(hObject, eventdata, handles)
> axes(handles.axes2)
> scatter(C1.struct.x,C1.struct.gsy)
> title('Monte Carlo Demo');
> xlabel('X data');
> ylabel('Y data');
> guidata(hObject, handles);
>
> but even though the struct is loaded in the workspace, the error
>
> ??? Undefined variable "C1" or class "C1.struct.x".
>
> comes up.
>
> Anyone have some input.
>
> Thanks in advanced-
>
> George

Add "data = load( filespec );" in the beginning of plotdata2_Callback ( the value of filespec has to be set somewhere). Unpack data which is a structure.

C1 = data.C1;

Store C1 with giudata or setappdata or somewhere so that you don't need to load data more than once per session.

/ per
 

Subject: Workspace variable to GUI

From: George Haralam

Date: 25 Aug, 2010 16:32:06

Message: 3 of 5

> Add "data = load( filespec );" in the beginning of plotdata2_Callback ( the value of filespec has to be set somewhere). Unpack data which is a structure.
>
> C1 = data.C1;
>
> Store C1 with giudata or setappdata or somewhere so that you don't need to load data more than once per session.
>
> / per
>

Thank you for the response. Im getting a bit more errors when I try the guidata. I am pretty new with GUIs so i believe im doing it wrong.

i have added this so far:

function plotadata_OpeningFcn(hObject, eventdata, handles, varargin)
data = load('datafile')
C1 = data.C1;
guidata(hObject,'C1')
set(hObject,'toolbar','figure');
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes plotadata wait for user response (see UIRESUME)
% uiwait(handles.figure1);


function plotdata2_Callback(hObject, eventdata, handles)
C1 = guidata(C1)
axes(handles.axes2)
scatter(C1.flare.gsx,C1.flare.gsy)
title('Monte Carlo Demo');
xlabel('GSX data');
ylabel('GSY data');
guidata(hObject, handles); %updates the handles

It saves C1 as something completely different.

Subject: Workspace variable to GUI

From: Sean

Date: 25 Aug, 2010 16:43:04

Message: 4 of 5

"George Haralam" <justajawn@gmail.com> wrote in message <i53gi6$ciq$1@fred.mathworks.com>...

> > Store C1 with giudata or setappdata or somewhere so that you don't need to load data more than once per session.

> Thank you for the response. Im getting a bit more errors when I try the guidata. I am pretty new with GUIs so i believe im doing it wrong.
>

Use setappdata, getappdata it's pretty painless.
setappdata(0,'C1',C1); %command line
C1 = getappdata(0,'C1'); %gui

Subject: Workspace variable to GUI

From: George Haralam

Date: 30 Aug, 2010 17:54:05

Message: 5 of 5

"Sean " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message <i53h6o$nc1$1@fred.mathworks.com>...
> "George Haralam" <justajawn@gmail.com> wrote in message <i53gi6$ciq$1@fred.mathworks.com>...
>
> > > Store C1 with giudata or setappdata or somewhere so that you don't need to load data more than once per session.
>
> > Thank you for the response. Im getting a bit more errors when I try the guidata. I am pretty new with GUIs so i believe im doing it wrong.
> >
>
> Use setappdata, getappdata it's pretty painless.
> setappdata(0,'C1',C1); %command line
> C1 = getappdata(0,'C1'); %gui

Thank you setappdata worked very well.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us