I want to open a dialog box for typing notes while my program is running. Then save those notes to a file.

4 views (last 30 days)
When I run a program, my program uses DIARY to store information that I FPRINT to the Console during program execution. I often take notes of what I see happening during my runs (my program controls test equipment). I want to type electronic notes in a Dialog Box, then automatically append those notes to my Automatically generated output file. This would be awesome - i'll never loose my notes and they are embedded in my output file !! Brian

Answers (1)

Joseph Cheng
Joseph Cheng on 18 Sep 2014
Edited: Joseph Cheng on 18 Sep 2014
Here is a simple code that you can adapt. if you want to try to run this create a GUIDE project that has only a button and an axes (with the default tag of axes1). Then paste this in the pushbutton callback.
NoteFig= figure;
figsize = get(NoteFig,'position');
editbox = uicontrol('parent',NoteFig,'style','edit','position',[20 20 figsize(3:4)-40],...
'HorizontalAlignment','left','max',2048);
pause(1)
tic;
n=1;
diary on
while toc<20
x(n) = toc;
y(n) = 5*sin(2*pi*x(n)/5);
disp(['plot value: ' num2str([x(n) y(n)]) ]);
plot(handles.axes1,x,y);
n=n+1;
pause(1)
end
h=msgbox('Simulation Done','Title');
notes = get(editbox,'string');
[r c]=size(notes);
Notes = mat2cell(notes,ones(r,1));
diary off
diary('diarytest.txt')
fid = fopen('diarytest.txt','a')
fprintf(fid,'%s\n\r',Notes{:});
fclose(fid);
so i'll walk you through the example. at the start i create a new figure with an edit box to type into. which i've scaled to fill the whole figure, made the horizontal alignment to be left and made the max number of new lines 2048.
I give some time to generate the new figure with pause(1) which i'm sure is way more time than it needs to display the notes entry. probably can get away with .1 or less.
then i created a dummy simulation code which plots a sin wave which also displays outputs in the command window.
so within the 20 seconds you can type in anything you want with the limit of 2048 lines!
at the end i pop a msgbox() to forces the focus off of the edit box thus updating the edit box data. I then append the edit box strings to the end of the diary notes file using fprintf. The only downside of this sample code is that i don't have time is to get rid of the padding of lines with spaces.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!