Print Command
Show older comments
Hello
Can anybody tell me that how to use the print command in matlab?
As i want to get the data from the textbox and print that particular data. not the whole figure.
Please anybody help..
2 Comments
Walter Roberson
on 15 May 2012
"print" is for creating the kinds of outputs that might be sent to a printer. Is that what you want? Or are you looking to create a text file?
Shavi
on 15 May 2012
Answers (1)
Walter Roberson
on 15 May 2012
Let h be the handle of the uicontrol of style Text. Then
h_handle = handle(h);
h_image = h_handle.getPrintImage;
At this point, h_image will be an RGB array containing a rendered copy of the text. You can now figure() a new figure, image() h_image into the new figure, and print() the new figure.
You might wish to consider, however, using imwrite() on h_image to save it to an image file that you can print using your system utilities.
I have my doubts that any of this is what you really want to do, but...
18 Comments
Shavi
on 16 May 2012
Shavi
on 16 May 2012
Walter Roberson
on 16 May 2012
print() cannot be used to print strings directly. print() can only be used to print figures. The code I gave constructs a new figure containing only an image of the text to be printed and prints that figure.
To have the figure sent directly to the printer, notice this section of the documentation: http://www.mathworks.com/help/techdoc/ref/print.html
Note On Windows systems, when you use the -P option to identify a printer to use, if you specify any driver other than -dwin or -dwinc, MATLAB writes the output to a file with an appropriate extension but does not send it to the printer. You can then copy that file to a printer.
Shavi
on 16 May 2012
Shavi
on 16 May 2012
Shavi
on 18 May 2012
Jan
on 18 May 2012
Please, Shavi, post more details. Are you working on Linux, MacOS or Windows? If you work with Windows, did you try the -dwin and -dwinc flags already? Did you read "help print" and "doc print"?
The current information level demands for too much guessing to allow for an efficient answer.
Shavi
on 22 May 2012
Jan
on 22 May 2012
The character | cannot be used in file names under Windows, see: http://windows.microsoft.com/en-us/windows-vista/file-names-and-file-name-extensions-frequently-asked-questions
Shavi
on 23 May 2012
Walter Roberson
on 23 May 2012
word1_handle = handle(word1);
word1_image = word1_handle.getPrintImage();
newfig = figure();
newaxes = axes('Parent',newfig);
image(word1_image, 'Parent', newaxes);
print(newfig, '-depsc', 'word1.eps');
delete(newfig);
%now at this point do whatever you need to in order to send word1.eps to the printer
I do not know how to command to send a file to a printer in MS Windows. Back in my day, printers were associated with parallel ports, and there was probably only one of them available, and the command back then was:
!copy word1.eps lpt:
Times have changed and you would, I am sure, use a different command. "NET PRINT" maybe.
Shavi
on 25 May 2012
Walter Roberson
on 25 May 2012
Which MATLAB version are you using? I tested in R2008b.
Shavi
on 25 May 2012
Shavi
on 25 May 2012
Walter Roberson
on 25 May 2012
I think I have access to that version at work; I will need to check tomorrow.
Shavi
on 25 May 2012
Walter Roberson
on 25 May 2012
Yes, I do have R2010b at work, and yes it does have getPrintImage
>> h = uicontrol('style','edit','String','hello there')
h =
0.0009765625
>> hh = handle(h)
hh =
uicontrol
>> methods(hh)
Methods for class hg.uicontrol:
getGUIDEView getPrintImage
>> hh.getPrintImage
ans(:,:,1) = [...]
Categories
Find more on Desktop in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!