Got Questions? Get Answers.
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:
problems using GUI

Subject: problems using GUI

From: Peter

Date: 6 Aug, 2010 14:30:24

Message: 1 of 2

I am trying to create a GUI to enable the user to edit a pair of arrays (databases) in a merging process.

I am having trouble with the GUI in accessing variables within pushbutton functions:

??? Undefined function or variable 'selectedcells1'.

Error in ==> GUI_test>pushbutton4_Callback at 128
[row1,columns1] = size(selectedcells1);

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> GUI_test at 42
    gui_mainfcn(gui_State, varargin{:});

Error in ==>
@(hObject,eventdata)GUI_test('pushbutton4_Callback',hObject,eventdata,guidata(hObject))

 
??? Error while evaluating uicontrol Callback

EDU>> whos global
  Name Size Bytes Class Attributes

  k 1x1 8 double global
  m1 1x1 8 double global
  m2 1x1 8 double global
  n1 1x1 8 double global
  n2 1x1 8 double global
  num 133x13 13832 double global
  num1 149x20 23840 double global
  num2 0x0 0 double global
  selectedcells1 1x2 16 double global
  selectedcells2 1x2 16 double global


how can my program tell me the variable is undefined, when it is a global variable? Also any direction towards a more correct method would be much appreciated since i have read that using global functions isn't a particularly good idea.

Subject: problems using GUI

From: Sean

Date: 6 Aug, 2010 15:44:05

Message: 2 of 2

"Peter " <dutton.peter@gmail.com> wrote in message <i3h6a0$gqa$1@fred.mathworks.com>...
> I am trying to create a GUI to enable the user to edit a pair of arrays (databases) in a merging process.
>
> I am having trouble with the GUI in accessing variables within pushbutton functions:
>
> ??? Undefined function or variable 'selectedcells1'.
>
> Error in ==> GUI_test>pushbutton4_Callback at 128
> [row1,columns1] = size(selectedcells1);
>
> Error in ==> gui_mainfcn at 96
> feval(varargin{:});
>
> Error in ==> GUI_test at 42
> gui_mainfcn(gui_State, varargin{:});
>
> Error in ==>
> @(hObject,eventdata)GUI_test('pushbutton4_Callback',hObject,eventdata,guidata(hObject))
>
>
> ??? Error while evaluating uicontrol Callback
>
> EDU>> whos global
> Name Size Bytes Class Attributes
>
> k 1x1 8 double global
> m1 1x1 8 double global
> m2 1x1 8 double global
> n1 1x1 8 double global
> n2 1x1 8 double global
> num 133x13 13832 double global
> num1 149x20 23840 double global
> num2 0x0 0 double global
> selectedcells1 1x2 16 double global
> selectedcells2 1x2 16 double global
>
>
> how can my program tell me the variable is undefined, when it is a global variable? Also any direction towards a more correct method would be much appreciated since i have read that using global functions isn't a particularly good idea.

You need to define it as global in the callback i.e.:
global celectedcells1

A better way:
doc setappdata
doc getappdata

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