Help: Matlab2010a figure output

Hi,
When I try to save the Matlab figure to an tiff file, there had some problem.
1) I used the command: >>print -dwin April05.tiff
The figure was saved but when opened it showed as a txt file and read:
%!PS-Adobe-2.0
%%Creator: MATLAB, The Mathworks, Inc. Version 7.10.0.499 (R2010a). Operating System: Microsoft Windows 7.
%%Title: .\April05.tif
%%CreationDate: 04/05/2011 18:09:51
%%DocumentNeededFonts: Helvetica
%%DocumentProcessColors: Cyan Magenta Yellow Black
%%Pages: (atend)
%%BoundingBox: (atend)
%%EndComments
Can any body help me with thiis issue?
2) Is there a way for me to save the figure to another path instead of the current work directory?

 采纳的回答

Andrew Newell
Andrew Newell 2011-4-7

0 个投票

Let's summarize what we know so far:
  1. The print command is creating a matrix with the correct dimensions and type, but you can't read it.
  2. We don't know yet whether you can view the image outside of MATLAB.
  3. You have the Image Processing Toolbox, so you should have imshow, but if you try using it you get an error saying there is no such function.
  4. which imshow -all returns "C:\Program Files\MATLAB\R2010a\toolbox\images\imuitools\imshow.m % Has no license available".
  5. You have tried rehash toolbox but it makes no difference.
I would still like to know the answer to (2), and you could try running imshow in C:\Program Files\MATLAB\R2010a\toolbox\images\imuitools\, but I think you probably have an installation problem and you should contact MATLAB Support.

更多回答(3 个)

Try
print -dtiff April05.tiff
or
print -dtiffn April05.tiff
(see the list of printer drivers in print, printopt.)
To view it, use these commands:
A = imread('April05.tiff');
imshow(A)
To save in some other folder, just replace April05.tiff by the full pathname or a relative pathname, e.g.,
print -dtiff ../April05.tiff
EDIT: you could also try
image(A)

21 个评论

Hi Andrew,
Thank you very much for your anwer. It was saved but after I type imshow(A) command, it shows "??? Undefined function or method 'imshow' for input arguments of type 'char'." Besides, if I just double click it, it pops up an "Import Wizard" window with "Create variables matching preview" checked. But after I click "Finish" on this window, it imported an "April05" matrix that cannot be displayed.
What's happening here?
Many thanks!
Wencai
Can you view the image outside of MATLAB?
It's odd that imread created a character array. What happens if you try it on a tiff image created outside of MATLAB?
After you do the imread(), what does it say the size and data class of A is ?
Thank you Andrew and Walter.
It's very strange to me that my other Tiff files now cannot be displayed correctly either. Even if I use the menu selection to "save as" a tiff, it cannot be opened. But the bad thing is it cannot be opened on other computers either...
Walter, the "April05" matrix size is 900x1200x3, the bytes is 3240000, and the classis unit8.
Wencai, what do you get if you type "which imshow -all"?
The matrix "April05" is consistent with a truecolor tiff image.
Hi Andrew,
It shows "C:\Program Files\MATLAB\R2010a\toolbox\images\imuitools\imshow.m % Has no license available"
I also just find "another way" to cause this problem:
Say if I have one "April05.fig" in "MyFileFolder", and an "April05.png" in the save folder. Unlike the tiff figure, both of these two figures can be opened normally.
Now if I open the "April05.fig" to edit it, for example, add one text. Then I click "save" on the menu for this figure.
It can be saved correctly if the "Save as type" is in "fig",
but it is saved as a matrix (the same as discussed above) if the "Save as type" is in "png".
So could there be the extention in my filename when using the command that has something besides "tiff"?
Wencai, that message "Has no license available" indicates that your trouble may have to do with your MATLAB license. If you type "ver", you'll see which toolboxes are available; for imshow you need the Image Acquisition Toolbox. If you think you should have this, you could try typing "rehash toolbox".
In answer to your other question - it should be saved as a matrix. I don't think your problem is saving the image - but did you try viewing April05.tiff using some other software?
Hi Andrew,
I didn't try open tiff with other software. Which one would you recommend?
Besides, if I save the file as an EMF file from "Save as" menu, it can be shown correctly after click open it.
However, the same problem occur if I use "print(gcf,EPSName)" where EPSName='April06-try.eps'
%!PS-Adobe-2.0
%%Creator: MATLAB, The Mathworks, Inc. Version 7.10.0.499 (R2010a). Operating System: Microsoft Windows 7.
%%Title: .\April06-try.eps (or April06-try.emf here)
%%CreationDate: 04/06/2011 17:42:39
%%DocumentNeededFonts: Helvetica
%%+ Helvetica-Oblique
%%DocumentProcessColors: Cyan Magenta Yellow Black
%%Pages: (atend)
%%BoundingBox: (atend)
%%EndComments
%%BeginProlog
% MathWorks dictionary
/MathWorks 160 dict begin
% definition operators
............
epage
end
showpage
%%Trailer
%%BoundingBox: 27 180 557 588
%%Pages: 001
%%EOF
What was the command that created this file?
As for opening the tiff file - I'm not that familiar with Windows, but if you right click it you'll get a menu of options.
I still suspect something is wrong with Matlab2010a. When I try to resave a fig figure to an EMF figure by "Save as", although the "Save as type" is showing "Enhanced metafile (*.emf)", the Filename doesn't get an "emf" extension. As a result, when I click "Save", it pops up saying the file.fig already exists.
The most important thing is, you need to type that "ver" command and see if you have the Image Acquisition Toolbox.
After rehash toolbox, there is still no Image Acq ToolBox.
O.k., but you do have the Image Processing Toolbox. Try these two commands (exactly as written):
I = imread('pout.tif');
imshow(I)
??? Undefined function or method 'imshow' for input arguments of type 'uint8'.
Copying Wencai's comment with license number censored
Oh, sorry didn't quite understand the comment.Here I got:
-------------------------------------------------------------------------------------
MATLAB Version 7.10.0.499 (R2010a)
MATLAB License Number: ######
Operating System: Microsoft Windows 7 Version 6.1 (Build 7600)
Java VM Version: Java 1.6.0_12-b04 with Sun Microsystems Inc. Java HotSpot(TM) 64-Bit Server VM mixed mode
-------------------------------------------------------------------------------------
MATLAB Version 7.10 (R2010a)
Control System Toolbox Version 8.5 (R2010a)
Curve Fitting Toolbox Version 2.2 (R2010a)
Image Processing Toolbox Version 7.0 (R2010a)
Signal Processing Toolbox Version 6.13 (R2010a)
Statistics Toolbox Version 7.3 (R2010a)
Wavelet Toolbox Version 4.5 (R2010a)

请先登录,再进行评论。

Lior Shapira
Lior Shapira 2011-4-6

0 个投票

Might not be what you're looking for, but the SC utility on the file exchange (http://www.mathworks.com/matlabcentral/fileexchange/16233-sc-powerful-image-rendering) converts figures to images, which you can then save with imwrite in whatever format you desire.

1 个评论

Thanks for your answer. I tried imwrite command, it also gives me the matrix when I open the saved figure file..

请先登录,再进行评论。

bym
bym 2011-4-6

0 个投票

Another one of Oliver's contributions could also help
http://www.mathworks.com/matlabcentral/fileexchange/23629-exportfig

1 个评论

Hi Proecsm, Thanks for this answer. However,now it seems to be the problem of file view.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by