MATLAB Answers

How would I create a GUI with a push button that when clicked, guy data will be save in .txt file?

6 views (last 30 days)
Jose Colon
Jose Colon on 14 Oct 2019
Answered: Jalaj Gambhir on 17 Oct 2019

  0 Comments

Sign in to comment.

Answers (1)

Jalaj Gambhir
Jalaj Gambhir on 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

  0 Comments

Sign in to comment.

Sign in to answer this question.