Plotting with MATLAB

Effective plots are important to synthesize the information into relevant and persuasive information. The following tutorial details some of the common data plotting functions within MATLAB.

Tutorial MATLAB Source Code

clear all; close all; clc
x = linspace(0,6);
y = sin(x);
z = cos(x);
h = figure(1);
plot(x,y,'r--')
hold on
plot(x,z,'b.-','LineWidth',3)
xlabel('x')
ylabel('values')
legend('y','z')
xlim([0 3]);
ylim([-1.5 1.5]);
saveas(h,'myPlot.png')
saveas(h,'myPlot.eps')

Resize Plot and Save Figures

clear all; close all; clc

x = linspace(0,10);
y = sin(x);

p1 = figure('rend','painters','pos',[10 10 900 600]);
plot(x,y)
legend('sin(x)')
ylabel('sin(x)')
xlabel('x')
saveas(p1,'myFigure1.png')

p2 = figure('rend','painters','pos',[10 10 300 200]);
plot(x,y)
legend('sin(x)')
ylabel('sin(x)')
xlabel('x')
saveas(p2,'Fig2_for_screens.png')
saveas(p2,'Fig2_for_documents.eps')

Additional Tutorials

This tutorial can also be completed with scripting programming languages like Excel and Python. Click on the appropriate link for additional information and source code.