Passing an array between GUI callbacks by using 'UserData'

  • Follow


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
0
Reply Robert 11/25/2009 5:14:18 PM

"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
0
Reply Dave 11/25/2009 6:05:20 PM


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
0
Reply Matt 11/25/2009 6:20:27 PM

2 Replies
279 Views

(page loaded in 0.047 seconds)

Similiar Articles:













7/30/2012 9:33:13 AM


Reply: