Effacer les filtres
Effacer les filtres

How to clear graphical objects

19 vues (au cours des 30 derniers jours)
Isaiah Slemons
Isaiah Slemons le 29 Mai 2019
Commenté : Adam Danz le 30 Mai 2019
I have a local function inside of my script that runs a gui (not GUIDE, just uicontrol in a figure) and creates a polyshape based on the selection I make in a drop down menu (which references a spreadhseet of values). My issue is that everytime I click the drop-down to select a different row of data, the previous data is just overwritten and I can't figure out how to clear the data iteratively on each pass of the function after clicking the drop-down.
I'd like to be able to view the graph that I create without clearing it automatically. I tried to clear the variables that assign the polyshape but that doesnt work because its inside the local function. So once it runs it can't remove those variables because the caller workspace is reset (thats my understanding of it). Do I need to use a nested function to query mouseclicks? Thanks in advance
  4 commentaires
Geoff Hayes
Geoff Hayes le 29 Mai 2019
Isaiah - save the handle to the polyshape object and then delete it just prior to creating the new shape. You may need to post some of your code so that we can see its structure, but if the callback is nested within the main function then you should be able to do this. For example, you might have
function myGui
% create the GUI
% assign the callbacks
% define the handle to the polyshape
hPolyshape = [];
% in your drop down callback
function dropDownCallback(~,~)
% delete the old polyshape
if ~isempty(hPolyshape)
delete(hPolyshape);
hPolyshape = [];
end
% plot the polyshape
hPolyshape = polyshape(...);
end
end
The above is very rough and will not compile but it gives you an idea of what you can perhaps do.
Isaiah Slemons
Isaiah Slemons le 29 Mai 2019
Geoff,
Thank you so much for helping me out with this. I posted a little more information under Adams comment and a snippet of code. Thanks in advance for the help.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 29 Mai 2019
Modifié(e) : Adam Danz le 29 Mai 2019
Prior to drawing the updated ployshape, clear the axes using cla() and always specify the axis handle.
cla(axHandle);
ployshape();
If the axis handle is not already available in the function's workspace or in the "handles" input to the callback function, you can get the axis handle by passing it into the plotting function or using findobj() or findall().
Alternatively you could toggle the hold() status.
hold(axHandle, 'off')
ployshape()
hold(axHandle, 'on') %if necessary
  4 commentaires
Isaiah Slemons
Isaiah Slemons le 30 Mai 2019
Adam. This information is so valuable. Thank you very much for your help.
Adam Danz
Adam Danz le 30 Mai 2019
I'm glad it was helpful!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by