Print Command

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 件のコメント

Walter Roberson
Walter Roberson 2012 年 5 月 15 日
"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
Shavi 2012 年 5 月 15 日
Ya i want to use the print command or print function.
I have to take the data from the text box and get it printed solely.
So what is the coding used for this?

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 5 月 15 日

0 投票

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 件のコメント

Shavi
Shavi 2012 年 5 月 16 日
Ya u r right, I am using Uicontrol.
I have used this coding
word1=[];
a=[];
word1 = get(handles.edit1);
a=fieldnames(word1);
l=getfield(word1,'String');
print('-depsc',l);
Now i am able to get the value of uicontrol, dats a good thing :)
But again the problem is with print command.
It is giving the following error
Cannot create output file '.\|O| |9| |8| |7| |6| |5| |4| |3| |2| |I| .eps'
where the string i am extracting is the above.
So can u tell where i am going wrong?
Shavi
Shavi 2012 年 5 月 16 日
Also the file having extension .eps or .ps is saved to the disk.\
but it is not going to the printer??
Walter Roberson
Walter Roberson 2012 年 5 月 16 日
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
Shavi 2012 年 5 月 16 日
Okay fine..
how to copy that file to printer?
Shavi
Shavi 2012 年 5 月 16 日
Also There is no property as specified getPrintimage.
Shavi
Shavi 2012 年 5 月 18 日
Plz reply!!
Jan
Jan 2012 年 5 月 18 日
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
Shavi 2012 年 5 月 22 日
Hello Jan Simon
I am working on windows platform.
Ya i have used these flags already. But if i used these flags then the output is
??? Error using ==> print at 364
Cannot create output file '.\|A| |B| |C| |D| |E| |F| |G| |H| |i| |J| |K| |L| |M| |N| |O|
|P| |Q| |R| |S| |T| |U| |V| |w| |X| |Y| |Q| |w| |E| |R| |T| |Y| |K| |E| |Y| |B| |O| |A|
|R| |D| |U| |S| |A| |N| |O| |M| |E| |N| |I| |2| |J| .eps'
Error in ==> smartform>print_Callback at 308
print('-dwin',l1);
Error in ==> gui_mainfcn at 96
feval(varargin{:});
Error in ==> smartform at 42
gui_mainfcn(gui_State, varargin{:});
Error in ==>
@(hObject,eventdata)smartform('print_Callback',hObject,eventdata,guidata(hObject))
??? Error while evaluating uicontrol Callback
This is the error which the system is showing. Plz help
I have explained as above my problem, if you want more details den write to me..
Thanks..
Jan
Jan 2012 年 5 月 22 日
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
Shavi 2012 年 5 月 23 日
ya i have corrected that.
The coding which i am using is
word1=[];
h=[];
a=[];
A=[];
word1 = get(handles.edit1);
l2=getfield(word1,'String');
print('-depsc',l2);
I want to print the value of l2 as it is the value of UIControl Text control.
But it is not working.
Tell me the solution plz..
Walter Roberson
Walter Roberson 2012 年 5 月 23 日
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
Shavi 2012 年 5 月 25 日
This code is giving this error:-
??? Error while evaluating uicontrol Callback
??? No appropriate method, property, or field getPrintImage for class handle.handle.
Error in ==> smartform>print_Callback at 325
word1_image = word1_handle.getPrintImage();
As there is no field, property or method named as getPrintImage.
Walter Roberson
Walter Roberson 2012 年 5 月 25 日
Which MATLAB version are you using? I tested in R2008b.
Shavi
Shavi 2012 年 5 月 25 日
Its R010b
Shavi
Shavi 2012 年 5 月 25 日
R2010b
Walter Roberson
Walter Roberson 2012 年 5 月 25 日
I think I have access to that version at work; I will need to check tomorrow.
Shavi
Shavi 2012 年 5 月 25 日
k
Walter Roberson
Walter Roberson 2012 年 5 月 25 日
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) = [...]

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeDesktop についてさらに検索

質問済み:

2012 年 5 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by