MATLAB: How to print the contents of a list or editable text box uicontrol

boxeseditlistboxMATLABprint

My original data is in a cell arry, and was put into the box using the standard method:
set(h, 'String', txt_cell);
Now I would like to print out the entire box.

Best Answer

MATLAB's File I/O routines can be used to print the contents of a list box to a text file. Once the text file is created use DOS or UNIX commands to send that text file to a printer. For example,
% Create some text and a list box
txt_cell = {'This is the first line';'This is the second';'This is the third'};
h = uicontrol('style','list',...
'Position',[20 20 200 80],...
'max',10,'min',1,...
'string',txt_cell);
% Use FPRINTF to write a text file
str = get(h,'String');
fid = fopen('myfile.txt','wt');
fprintf(fid,'%s \n',str{:});
fclose(fid);
% Verify that the text file was created
type myfile.txt
This is the first line
This is the second
This is the third
% Use DOS to print the text file to a printer
!copy /b myfile.txt lpt1:
1 file(s) copied.