How to save an axes into an matlab figure after plotting through button down function?

I have an application to save an axes data into matlab figure after ploting some data into axes.
The action need to be done through axes button down function.
But, the button down fuction is not working after ploting the data into the axes.

10 commentaires

"Not working" doesn't tells us anything. If there is an error message, share the entire error message. If there is unexpected behavior, describe your expected behavior and the actual behavior. It's usually helpful to provide the callback function so we can see what's going on inside. I presume the callback is merely calling the saveas function or something similar (exportgraphics, maybe?).
After ploting the data on axes, the buttondown function is unresponsive.
When we click on the axes, the buttondown function is not getting enabled. No error msg also.
Before ploting the data on axes, the buttondown function is working fine.
Adam Danz
Adam Danz le 12 Juin 2021
Modifié(e) : Adam Danz le 12 Juin 2021
Have you tried to apply the button down function to the axes after the plotting? I have a feeling that adding the plot clears the button down fcn.
Then, how can we save the plotted axes data into a matlab figure?
Previously, i have written the command 'copyobj(handles.axes3,figure)' in button down function of the axes. it does'nt working after plotting.
As Adam notes, I think you need to post your code creating the axes and that assigns the callback functions as well as the callback function itself...nobody can debug what can't see.
Easiest would be to create a toy project that illustrates the problem that could be downloaded directly...
I have no idea what you're doing. Please explain how you're creating the plot, when and how you're assigning the buttonDownFcn and all of the details necessary to explain the problem.
Sorry for the inconvenience.
I am sharing the create & buttondown function here.
function axes3_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
plot([0 20],[50 1500]);
function axes3_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
copyobj(handles.axes3,figure);
Oh, so this is done in GUIDE. Where/how are you assigning the buttonDwnFcn to the axes?
Is that done in GUIDE or from a startup function or somehwere else? Please share that line(s) of code where you're assigning the ButtonDownFcn to the axes.
The axes created in GUIDE and assigned button down function GUIDE itself.
But we don't have that code to look at so still can't diagnose anything at all without spending our time trying to recreate your symptoms. "Help us help you..."

Connectez-vous pour commenter.

 Réponse acceptée

Adam Danz
Adam Danz le 13 Juin 2021
Modifié(e) : Adam Danz le 13 Juin 2021
I created a GUIDE-based GUI containing the two functions you mentioned and was able to reproduce the problem (in the future, you should create a simple example demo to make it easy for people to reproduce and diagnose the problem).
When objects are plotted to the axes, the ButtonDownFcn is cleared which is why the ButtonDownFcn worked before plotting but didn't work after plotting.
To fix it, hold the axes before plotting.
% --- Executes during object creation, after setting all properties.
function axes1_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
hold(hObject, 'on') % <-------- ADD THIS --------------------
plot(hObject, [0 20],[50 1500]);
Another solution would be to programmatically assign the ButtonDownFcn after the plotting.

Plus de réponses (0)

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by