How to clear the value from a numeric or text edit field on Matlab App Designer?

123 views (last 30 days)
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.
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?
I have tried that whenever Refresh button is clicked:
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?

Accepted Answer

Cris LaPierre
Cris LaPierre on 8 Jan 2021
Edited: Cris LaPierre on 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

More Answers (2)

Mario Malic
Mario Malic on 8 Jan 2021
Edited: Mario Malic on 8 Jan 2021
All looks good, except double equal marks, you can create a (helper) function that would do that
function ClearFields(app)
In the button callback you would just call the function
function ButtonPushedFcn(source, event)

sing on 20 Apr 2022
Edited: sing on 20 Apr 2022
A workoaround solution is to set the color of the text equal to the box's background (typically white).
In your case:
app.editfieldN.FontColor=[1 1 1]


Find more on Develop Apps Using App Designer in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!