MATLAB: How to import user inputs from a GUI into a text documents

gui

How do I import user inputs from a GUI into a text documents?
I am trying to create a planner type GUI that allows the user to input: task and due date. The programs writes this data into a notepad file, but each time the user inputs a new input, it overwrites what was in the notepad.
a=get(handles.edit2,'string')
b=get(handles.edit3,'string')
c=sprintf(' Your %s is due %s ',a,b)
da={a,b};
fid=fopen('data.txt','w');
fprintf(fid,'%s \t %s \r\n','Assignment Name','Due Date')
importdata data.txt
fprintf(fid,'%10s \t\t %10s \r \n',a,b)
fprintf(fid,'%10s \t\t %10s \n',a,b)
fclose(fid);
d=set(handles.text7,'string',c)

Best Answer

Change

fid=fopen('data.txt','w');

to

fid=fopen('data.txt', 'at');

and get rid of the \r (which you have used inconsistently anyhow.)

https://www.mathworks.com/help/matlab/ref/fopen.html#btrnibn-1-permission

Using 'w' is defined to erase the existing contents; using 'a' is defined to append at the end of file.