How to clear the value from a numeric or text edit field on Matlab App Designer?
60 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
ErikJon Pérez Mardaras
le 8 Jan 2021
Modifié(e) : Cris LaPierre
le 4 Avr 2023
As you can see in the following image, I have an app.editfield (numeric) called app.editfieldN and another app.editfield (text) called app.editfieldT, as well as a refresh button called app.Button.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/482303/image.png)
The point is that, when I run the app, and when values are introduced in those editfields (as you can see in the following image), I would like to reset/clear/delet those values when clicking on the refresh button. How can I achieve that?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/482308/image.png)
I have tried that whenever Refresh button is clicked:
app.editfieldN.Value=='0';
app.editfieldT.Value==' ';
It does "clear" the editfields but It doesn't seems very professional and I think that it distorts following values that will be entered in the future.
So, there is any professional/right way of clearing/deleting does values appart from mine?
0 commentaires
Réponse acceptée
Cris LaPierre
le 8 Jan 2021
Modifié(e) : Cris LaPierre
le 8 Jan 2021
There is a syntax error in your code. You assign values with a single equals sign. You compare values with two equal signs. Also, a numeric edit filed should be assigned a numeric value. You are assigning it a text value because zero is in quotes.
This is the approach i would probably take given what I know about your app. My code would be
app.editfieldN.Value=0;
app.editfieldT.Value='';
2 commentaires
KEE OOI TING
le 4 Avr 2023
Is there any way to clear all editfield? My app is to receive user input for a prediction model, but I want to let them clear the boxes every time they want to start over.
Cris LaPierre
le 4 Avr 2023
Modifié(e) : Cris LaPierre
le 4 Avr 2023
There is no single command that will clear all components. You will need to write code for each component you want to clear.
Plus de réponses (2)
Mario Malic
le 8 Jan 2021
Modifié(e) : Mario Malic
le 8 Jan 2021
Hello,
All looks good, except double equal marks, you can create a (helper) function that would do that
function ClearFields(app)
app.editfieldN.Value=0;
app.editfieldT.Value='';
end
In the button callback you would just call the function
function ButtonPushedFcn(source, event)
ClearFields(app)
end
0 commentaires
Voir également
Catégories
En savoir plus sur Create System Objects 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!