Reusing deleted figure handle

11 visualizaciones (últimos 30 días)
TastyPastry
TastyPastry el 7 de Oct. de 2015
Comentada: Adam el 7 de Oct. de 2015
I have a GUI which displays several axes (array of axes) that the user can switch between to plot on. Here's what the relevant portion looks like:
The issue I'm running in to is that I have a delete button (not shown) which deletes an axes using delete(handle), but I'd like to implement an undo button (not shown). When an axes is deleted, the code stores it and the index in the array in case the user undoes the operation. During the undo, the deleted axes is restored to the previous location in the array. There's a line of code:
axes(plotWindow.plot(lastAxesInd));
%plotWindow is the GUI
%plotWindow.plot is the array of plots
%lastAxesInd is the index of the axes which was deleted. it is being inserted back to the same location
which is meant to switch the focus of the GUI to the restored axes. This causes Matlab to crash, which I'm assuming is because I'm trying to switch focus to a handle which has been deleted.
What can I do to go around this issue? I'd like to not have to append a new axes to the end of the array, since I use the axes' indices as a way to track which plot the user is plotting on, shown above.
  5 comentarios
TastyPastry
TastyPastry el 7 de Oct. de 2015
Editada: TastyPastry el 7 de Oct. de 2015
Yeah I figured I'm just going to stick with setting the "deleted" axes to 'visible','off', even though that leaves a trail of deleted axes in my array if the user deletes a ton of them. This also makes restoring a lot easier since I just need to change 'visible','on' and refocus the GUI on the restored axes.
Adam
Adam el 7 de Oct. de 2015
I don't really know what the overhead is of non-visualised axes, though it depends more what is plotted on them since the data will remain in memory.
Permanently deleting all previously deleted axes is easy though. As I said, so long so long as you keep the index of the one the user just selected to delete you can hide that one, but delete the previously "hidden" one because it can now never be restored by the user. Just don't physically delete the very latest one that might be restored.

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 7 de Oct. de 2015
Editada: Stephen23 el 7 de Oct. de 2015
How about simply keeping all of the axes (no deleting!) and switching the axes' visibility property on and off? Then all of your axes handles remain valid for as long as the axes exist, even if they are not visible.
  2 comentarios
TastyPastry
TastyPastry el 7 de Oct. de 2015
I did do some research beforehand and there were several solutions where the user changed visibility, but I'd like for any deleted axes to be removed from the plotWindow.plot array. I have the part of the UI where there's a box between "Previous" and "Next" (shown above), which tracks the index of the plot the user is working on. If I were to delete say, plot 4 of 7 and make it not visible, then when the user presses "Next" on plot 3, they would see a blank plotting area because the figure exists, but is invisible. I'm thinking I have to create a map which tracks which figures are not deleted.
TastyPastry
TastyPastry el 7 de Oct. de 2015
On second thought, it's easier to restore the axes if I just keep all the created ones. It'll create a trail of unused axes if the user just deletes stuff a lot. Would it make that big of a difference in performance/memory usage if I also deleted axes not covered by the undo button? I could have the program clean up inactive axes by deleting them.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by