How would I create a GUI with a push button that when clicked, guy data will be save in .txt file?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/242671/image.png)
0 commentaires
Réponses (1)
Jalaj Gambhir
le 17 Oct 2019
Hi,
You can do so by adding a SaveFileButtonPushed() callback. In this function you can access the values of the fields and dump it to text file using fprintf, as shown below:
function SaveFileButtonPushed(app, event)
name = app.NameEditField.Value;
age = app.AgeEditField.Value;
sex = app.SexEditField.Value;
height = app.HeightEditField.Value;
fileID = fopen('data.txt','w');
fprintf(fileID,"%s\t%s\t%s\t%s\t",name,age,sex,height);
end
end
1 commentaire
Salina
le 11 Juil 2022
In this very example you gave, how to keep on adding the data to the text file on every click?
Voir également
Catégories
En savoir plus sur Environment and Settings 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!