Save figure as PDF (and PNG)

function saveasPDF(h, filename)% Eg. saveasPDF(gcf, sprintf('Filename'))fig = h;% fig.PaperPositionMode = 'auto';set(fig,'PaperPositionMode', 'auto');fig_pos = fig.PaperPosition;fig.PaperSize = [fig_pos(3) fig_pos(4)];

% get(gca, 'ylim')% try% set(gca, 'ylim', [min([0, get(gca, 'ylim')]), max(get(gca, 'ylim'))])% endtitle([])set(gca, 'LooseInset', get(gca, 'TightInset'));
% print(fig, filename, '-dpdf', '-bestfit')print(fig, filename, '-dpdf', '-bestfit', '-painters')% print(fig, filename, '-dpdf')% close(fig)
% print(fig, regexprep(filename, '.pdf', '.png'), '-dpng', '-r0')print(fig, regexprep(filename, '.pdf', '.png'), '-dpng', '-r600')
end

Shade x-axis

function shadex(x1, x2)% Shades current figure from x1 to x2hold onylimits = get(gca, 'ylim'); % Get y axis limits colour = [0.4, 0.4, 0.4]; % Greyp = fill([x1, x2, x2, x1], sort([ylimits, ylimits]), colour);set(p, 'FaceAlpha', 0.25, 'EdgeColor', 'none'); end

Note:

Works with MATLAB R2017a and not 2016a

Disclaimer

The content posted on this website are for personal use only. The material is intended for educational purposes only.No part of this may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage and retrieval system, without prior written permission of the author.The author accepts no liability in any event including (without limitation) negligence for any damages or loss of any kind, including (without limitation) direct, indirect, incidental, special or consequential damages, expenses or losses arising out of, or in connection with your use or inability to use the information in the material. Use this material at your own discretion.