Deleting plots in app designer

41 vues (au cours des 30 derniers jours)
Kevin P Meyer
Kevin P Meyer le 18 Août 2021
I am doing this project in app designer. I have a scatter plot of a data set in the UIAxes and I am wanting to use polyfit to fit a line to the data. I have a spinner that will change to the degree of the polynomial that the user wants. So that when the spinner is set to 1, the polyfit is set to a polynomial with degree 1 and plots that on the UIAxes. When I change it to 2, its set to a polynomial of degree 2 and plots a new polynomial of best fit. The problem I have encountered is that when I do another plot it plots over the one that is already there and does not delete the previous one. I am not sure how to fix this. I used the delete() and set('Visible','off') functions but it did not work. I think the problem may be that I am setting the plot command equal to the same variable I am using for all of them? I have attached a copy of the code in question. ContrastV/ContrastH vs spatial_f are my data points, so there are two plots.This code is the function for a value changed function callback. Really the only code to pay attention to here is the first two IF statements and the last IF statement. If anybody could tell me how to fix this that would be awesome! There is also a warning that variables are used before they are defined, which is why I have the first two if statements, and the last two warnings are that the variables are not used in the code. THis is because it has to plot before it can delete them.

Réponses (1)

Cris LaPierre
Cris LaPierre le 18 Août 2021
Turn hold off. Best practice is to pair a hold on with a hold off.
Do not turn hold on until the first plot has been created.
Another approach is to use cla
cla(app.UIAxes)
  1 commentaire
Prajwol Tamrakar
Prajwol Tamrakar le 9 Août 2023
Modifié(e) : Prajwol Tamrakar le 9 Août 2023
See app.UIAxes.Children!! Each plot you created will be included here. The latest plot will be included on top. If you have four line plots, you can delete the first one by using "
delete(app.UIAxes.Children(4))
. Similary, use
delete(app.UIAxes.Children(1))
to delete the latest plot. Hope this is helpful!!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Linear and Nonlinear Regression dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by