MATLAB: How to create a polar plot on an axis object and then save it by clicking the “save” button using GUIDE

guideMATLABplotpolarsave

How can I create a polar plot on an axis object and then save it by clicking the "save" button using GUIDE?
I am trying to put a polar plot on a GUI that I am developing using GUIDE. I would like to save it when the user clicks on the "save" button, but I am encountering an error message saying "handle to deleted Axes".

Best Answer

The reason for this error message is most likely because you are trying to save the polar plot by accessing the handle after it is no longer available in the Workspace.
In order to avoid the error message, you can test if the handle is for an existing graphics object by using the "ishghandle" function before trying to save it. Then, you can save the plot only if the handle exists. Refer to the following link for more information on using the "ishghandle" function:
Attached is an example GUI and code (TSExample.fig, and TSExample.m). This example demonstrates how you can create an axis using GUIDE, and then have a polar plot on a polar axis. Furthermore, when you click the "Save" button on the GUI, the polar plot is saved by executing the "saveas" function in the callback function for the "Save" push button.
Follow the below steps to execute the example:
1. Execute the "TSExample.m" code. Then, you can see the axes, and the polar plot.
2. Click on "Save" button on the GUI. This will save the polar plot to a PNG file named "examplePolar.png" in the current working directory.
Thus, this example demonstrates how to plot a polar plot on a GUI axes and then save it.