How would I create a GUI with a push button that when clicked, guy data will be save in .txt file?
2 次查看(过去 30 天)
显示 更早的评论
回答(1 个)
Jalaj Gambhir
2019-10-17
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 个评论
Salina
2022-7-11
In this very example you gave, how to keep on adding the data to the text file on every click?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!