From: Bart on
I am making a GUI with multiple images that are plotted with the imagesc(data) command. As far as I can tell imagesc is different from plot and I am not able to pass the image a handle, so to get around this I use the axes command to set the current figure. But when I do this I lose all my settings that I created with the Matlab GUI tool. The one that I specifically want to preserve is the ButtonDownFcn. To try to get around this I have been saving some of the information in temp variables and setting that data after the image is created, but I am missing something for the button down function. Below is how I am doing this. The ButtonDownFcn works before I place data in the plot, but not after so I think I am losing it in this code, specifically the imagesc(data) command.

% Find the handle to the object I want to save
myImageHandle = findobj('Tag','imageOne');
% save the tag
tempTag = get(myImageHandle,'Tag');
% I hoped this would save the ButtonDownFcn but it doesn't seem to be working
tempButton = get(myImageHandle,'ButtonDownFcn');

%set the current figure
axes(myImageHandle);

% The imagesc(data) command overwrites the figure i created and all of my data is lost
% that is why I save relevant data in the variables above but I am missing something
imagesc(data);

%reset the saved variables
set(myImageHandle,'Tag',tempTag);
set(myImageHandle, 'ButtonDownFcn', tempButton);

I hope I explained myself clearly and correctly. Any help would be greatly appreciated. Also this code was retyped not cut and pasted so any typos are just mistakes and not crashing the program.

Thanks,

Bart
From: Steven Lord on

"Bart " <none(a)aol.com> wrote in message
news:i14hg0$gdj$1(a)fred.mathworks.com...
>I am making a GUI with multiple images that are plotted with the
>imagesc(data) command. As far as I can tell imagesc is different from plot
>and I am not able to pass the image a handle

You mean an axes handle to use as parent? You can, but in a slightly
different way. Use the imagesc(..., 'PropertyName', PropertyValue, ...)
syntax to set the Parent property of the image.

> , so to get around this I use the axes command to set the current figure.
> But when I do this I lose all my settings that I created with the Matlab
> GUI tool. The one that I specifically want to preserve is the
> ButtonDownFcn. To try to get around this I have been saving some of the
> information in temp variables and setting that data after the image is
> created, but I am missing something for the button down function. Below
> is how I am doing this. The ButtonDownFcn works before I place data in
> the plot, but not after so I think I am losing it in this code,
> specifically the imagesc(data) command.

High-level plotting functions, like PLOT and IMAGESC, respect the NextPlot
property of the axes and the figure into which you're plotting. This
document explains how that causes the behavior you're describing and how to
avoid it.

http://www.mathworks.com/support/solutions/en/data/1-168SX/?solution=1-168SX

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com


From: Bart on
Steve,

Thanks for that post it explains a lot on how things work. So I looked at that and changed my code but I still have the same problem.
The new code is

% Find the handle to the object I want to save
myImageHandle = findobj('Tag','imageOne');

% Set this to save the properties
set(myImageHandles,&#8217;NextPlot&#8217;,&#8217;add&#8217;)

%set the current figure
axes(myImageHandle);

% The imagesc(data) command overwrites the figure i created and all of my data is lost
% that is why I save relevant data in the variables above but I am missing something
imagesc(data);

I still lose the buttonDownFcn with this setup, but if I comment out the imagesc(data) the function works as expected. Is there something else I am missing?

Thanks,

Bart
From: Bart on
Ignore my last message, the ButtonDownFcn works if you click on the edge of the plot where the x and y tickmarks are. I am a little confused by that and thought they would work throughout the plot, not just on the outside edge. Is that they way they operate?

Thanks,

Bart
From: Frédéric Bergeron on
"Bart " <none(a)aol.com> wrote in message <i14kl8$dqg$1(a)fred.mathworks.com>...
> Ignore my last message, the ButtonDownFcn works if you click on the edge of the plot where the x and y tickmarks are. I am a little confused by that and thought they would work throughout the plot, not just on the outside edge. Is that they way they operate?
>
> Thanks,
>
> Bart

Hey,

I'm programming a GUI with surface and mesh plots, so I don't know if what I think may apply to image plots, but the 'hittest' property for a lots of my plot has been a problem for buttondownfcn. I have to desactivate this function (i.e set(h,'hittest','off') ), for my buttondownfcn to works, because this property makes (I think) that when you click on a plot with 'hittest' set to on, it just select the plot and make nothing else, so it ignores the buttondownfcn.
So you may want to check if the 'hittest' property is availlable for your image plots, because as I said I work with surf and mesh plot, so I don't know if this property is used in image plots.

Bye,
Fred