Saving a 1xn Bar plot as a jpg

조회 수: 1 (최근 30일)
Trigg Allen
Trigg Allen 2020년 10월 30일
편집: Ameer Hamza 2020년 10월 30일
Hello,
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
test = bar(y)
I want to save this bar plot as an image programatically. I have no issues saving a 1x1 Bar using saveas(), but when I have a 1xN Bar then I get this errorr:
Error using checkArgsForHandleToPrint
Can print only one page at a time.
Error in checkArgsForHandleToPrint
Error in print>LocalCreatePrintJob (line 101)
handles = checkArgsForHandleToPrint(0, varargin{:});
Error in print (line 38)
[pj, inputargs] = LocalCreatePrintJob(varargin{:});
Error in saveas (line 181)
print( h, name, ['-d' dev{i}] )
How can I programatically save a 1xN bar plot?

답변 (1개)

Ameer Hamza
Ameer Hamza 2020년 10월 30일
편집: Ameer Hamza 2020년 10월 30일
saveas() is quite an old function and not suitable for getting high-quality images. If you are using a recent version of MATLAB, then try exportgraphics()
y = [2 2 3; 2 5 6; 2 8 9; 2 11 12];
bar(y)
exportgraphics(gcf, 'filename.jpg', 'Resolution', 300)
If you are using an older version which does not have exportgraphice() then use this FEX package: https://www.mathworks.com/matlabcentral/fileexchange/23629-export_fig

카테고리

Help CenterFile Exchange에서 Printing and Saving에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by