Info
This question is closed. Reopen it to edit or answer.
How can I retrieve time stored in a variable and print it next to previous time in a text file in Matlab.
2 views (last 30 days)
Show older comments
I am working on a time stamp code using GUI. I have four radio buttons in my interface and I want to stamp the date and start and end time when I press each radio button. This means that every time I select a radiobutton, I want that time related to it to be stored and printed as the end time of the last selected radiobutton and the start time of the currently selected radiobutton. My problem is that the endtime winds up being less than the start time and I don't know how to correct that. I would really appreciate some help. Thanks!
function uibuttongroup1_SelectionChangedFcn(hObject, eventdata, handles)
filename = 'test.txt';
fileID = fopen(filename,'at');
A = get(hObject,'String');
date = datetime('now','Format','MM/dd/yyyy');
dat = char(date);
time = datetime('now','Format','HH:mm:ss');
currentTime = char(time);
endtime = getappdata(0,'futuretime');
endtime = char(endtime);
%elapsedtime = char(time - prevTime);
fprintf(fileID,'%s\n',[]);
fprintf(fileID,'%s\t %s\t %s\t %s\n',A,dat,currentTime, endtime);
fclose(fileID);
setappdata(0,'futuretime',time);
0 Comments
Answers (1)
Walter Roberson
on 29 Dec 2015
You are getting your "endtime" from the existing getappdata(0,'futuretime') which was set by a previous call's current time. "endtime" is going to be in the past. You should be expecting it to be before your current time. You seem to have your past and future reversed.
1 Comment
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!