Skip to content

Instantly share code, notes, and snippets.

@kpsychas
Last active October 19, 2015 20:54
Show Gist options
  • Save kpsychas/89107d2e3ec284574dfc to your computer and use it in GitHub Desktop.
Save kpsychas/89107d2e3ec284574dfc to your computer and use it in GitHub Desktop.
A file that can act as a template to create a non trivial Matlab plot and save it to png
close all; clear all;
t = -5*pi:1e-3:5*pi;
y1 = sin(t);
y2 = cos(t);
y3 = 0.6*y1 + 0.8*y2;
y4 = 0.8*y1 + 0.6*y2;
figure('Name','Graph','Color','w','Position',[10 30 600 400]);
set(subplot(2,1,1),'ylabel',text('string', 'Amplitude'),...
'title',text('string', 'Trigonometric functions'),...
'xlim', [t(1) t(end)], 'ylim', [-1.1 1.1],...
'Fontsize', 14);
hold on; plot(t,y1); plot(t,y2); hold off;
legend('sin', 'cos', 'Location', 'SouthEast');
set(subplot(2,1,2),'xlabel',text('string', 'Time [ms]'),...
'ylabel',text('string', 'Amplitude'),...
'title',text('string', 'Trigonometric functions(shifted)'),...
'xlim', [t(1) t(end)], 'ylim', [-1.1 1.1],...
'Fontsize', 14);
hold on; plot(t,y3); plot(t,y4); hold off;
legend('0.6sin + 0.8cos', '0.8sin + 0.6cos', 'Location', 'SouthEast');
print(gcf,'-dpng','-r100','plotfile');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment