Thread Subject: Passing an array between GUI callbacks by using 'UserData'

Subject: Passing an array between GUI callbacks by using 'UserData'

From: Robert Berry

Date: 25 Nov, 2009 17:14:18

Message: 1 of 3

Hello,

I have an issue with MATLAB GUIs that I don't know how to solve. I've looked through so many tutorial GUIs and it's driving me crazy that such a simple thing isn't addressed in all the materials I've seen.

I'm creating a GUI that adjusts various aspects of an image (brightness, contrast, etc) in a GUI using sliders, pushbuttons, and the like. I want to read the image ONCE into an array (done), display the image (done), and then pass the array between callbacks so that when they are executed (i.e. slider value change) the array values can be altered, the display window is updated, and the new image array can be passed again.

I have tried using the image axis (where the image is displayed) as the data repository by using

set(handles.ImageAxis,'UserData', ImageDataArray);
%ImageDataArray is an array of image data
%ImageAxis is the tag of the image window in the GUI

within a callback. This seems to work when I put breakpoints in to test the set() command. But when I try to pass the data

ImageDataArray = get(handles.ImageAxis,'UserData');

in another callback it returns a blank array. I....am...stuck. If there is a great example of how to do this please direct me to it.

Thanks in advance for the help. I am extremely grateful.
Robert

Subject: Passing an array between GUI callbacks by using 'UserData'

From: Dave Robinson

Date: 25 Nov, 2009 18:05:20

Message: 2 of 3

"Robert Berry" <berrypioneering@gmail.com> wrote in message <hejola$edu$1@fred.mathworks.com>...
> Hello,
>
> I have an issue with MATLAB GUIs that I don't know how to solve. I've looked through so many tutorial GUIs and it's driving me crazy that such a simple thing isn't addressed in all the materials I've seen.
>
> I'm creating a GUI that adjusts various aspects of an image (brightness, contrast, etc) in a GUI using sliders, pushbuttons, and the like. I want to read the image ONCE into an array (done), display the image (done), and then pass the array between callbacks so that when they are executed (i.e. slider value change) the array values can be altered, the display window is updated, and the new image array can be passed again.
>
> I have tried using the image axis (where the image is displayed) as the data repository by using
>
> set(handles.ImageAxis,'UserData', ImageDataArray);
> %ImageDataArray is an array of image data
> %ImageAxis is the tag of the image window in the GUI
>
> within a callback. This seems to work when I put breakpoints in to test the set() command. But when I try to pass the data
>
> ImageDataArray = get(handles.ImageAxis,'UserData');
>
> in another callback it returns a blank array. I....am...stuck. If there is a great example of how to do this please direct me to it.
>
> Thanks in advance for the help. I am extremely grateful.
> Robert

I have seen problems that sound similar to yours. Invariably its because I forgot to include the following line at the end of my callback

% Update handles structure
guidata(hObject, handles);

Hope that helps

Dave Robinson

Subject: Passing an array between GUI callbacks by using 'UserData'

From: Matt Fig

Date: 25 Nov, 2009 18:20:27

Message: 3 of 3

There are better methods than using userdata, although it can be done.

See the example answer to question number 16, 21 and others.

http://www.mathworks.com/matlabcentral/fileexchange/24861-35-complete-gui-examples

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
handle graphics Robert Berry 25 Nov, 2009 12:19:23
image processing Robert Berry 25 Nov, 2009 12:19:23
callbacks Robert Berry 25 Nov, 2009 12:19:23
slider Robert Berry 25 Nov, 2009 12:19:23
contrast Robert Berry 25 Nov, 2009 12:19:23
gui Robert Berry 25 Nov, 2009 12:19:22
rssFeed for this Thread

Contact us at files@mathworks.com