MATLAB Answers

make axes bigger when mouse clicked

2 views (last 30 days)
best16 programmer
best16 programmer on 25 Apr 2017
Commented: AstroGuy1984 on 25 Apr 2017
hi matlab community,i am a begginer in matlab gui, i have 7 axes in my gui i don't know if it's possible that when I click or pass the mouse on one of the axes it will be shown bigger in the middle of the gui. thanks for advance


Sign in to comment.

Answers (1)

AstroGuy1984 on 25 Apr 2017
When you say "7 axes" are you meaning 7 separate axes objects or 7 series within a singular axes object? I am assuming you mean 7 separate plots and you want to be able to "blow up" a clicked plot into the main plot.
Nonetheless, I believe where you will want to start with is the ButtonDownFcn property within the Axes object in question. So when you instantiate your axes object, set the property there as such:
axes('Parent', fig_handle, ..., 'ButtonDownFcn', @function_name);
where ... are all the other properties for your axis when you create it. If you are using GUIDE, you can just set that one property in the normal way using:
set(axes_handle, 'ButtonDownFcn', @function_name);
From there you will want to make a callback function (name it whatever you are setting the ButtonDownFcn to be) and give it similar arguments to what you'd get in a regular callback:
function function_name(hObject, event)
hObject will be the Axes object clicked and the event object will contain a property to tell you where it was hit. From there, you now know what plot was clicked for copying into a larger plot.
It's hard to tell you where to go from there without knowing about the destination, but I'd heavily suggest using the copyobj() function for copying series within a plot.


Show 1 older comment
AstroGuy1984 on 25 Apr 2017
So what you will want to do is make a separate function in your m-file that will run upon "clicking" the axes object. When you set the 'ButtonDownFcn' property you are telling the axes object to run that function when it is clicked.
Name it whatever you want, I just called it function_name, but let's make it clearer and call it "axesClicked_Callback". You can have all axes share the same function, which makes life easier as well. For a given axes, you want to set the property 'ButtonDownFcn' to @axesClicked_Callback. From there, you will want to make a function elsewhere in your m-code that is that function:
function axesClicked_Callback(hObject, event)
% hObject will be the handle to the Object calling the func
% event will be details about what happened
From what I can tell from your question, you won't actually need anything in "event" but both hObject and event will be automatically passed to the callback function upon clicking the axes.
From there, you're going to know what axes was clicked! (it will be hObject). I'm assuming you have another 8th Axes object that is your place for the "blown up" plot to appear? If not, you can easily make one as well.
What I have done in the past when copying one plot to another in a GUI is to copy out the children one by one using the copyobj() function. This will copy any data series you want from the source function into a new variable.
For example:
for i = 1:numel(hObject.Children)
copyobj(hObject.Children(i), destination_Axes);
From there, you can copy formatting or whatever else you want, but the basic stuff you want should be in the destination axes.
Hope this helped to clarify things.
best16 programmer
best16 programmer on 25 Apr 2017
i really appreciate your help,can you please give me an example of how the code in function axesClicked_Callback should be.thank you
AstroGuy1984 on 25 Apr 2017
I am only able to provide a guess like I did above (looping into the children of the source axes and copying them into the destination axes). Likewise, you can copy over any other properties you wish to.
Do you have the destination axes drawn or do you wish for it to appear upon click? You are going to want to reference that axes as the destination object like in the loop above.
If you used that loop inside the axesClicked_Callback() function above, that will be a good start, and hopefully get you in a position where you can figure out what other things you want to copy. You're going to need the destination axes handle if it already exists, and you'll need to make one if you're drawing the new plot within the function.

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by