Saving plot with multiple inputs

1 view (last 30 days)
% "Produce a single plot containing the horizontal displacement
% as a function of time from the recorded data"
x = 1:0.01:10
y = x.^2
z = x.^3
a = plot(x,y,x,z)
xlabel('Time (seconds)')
ylabel('Horizontal displacement (m)')
title('Part 5')
legend('Attempt 1', 'Attempt 2')
saveas(a,'Plot 5.jpg')
Trying to save a plot with multiple inputs into a jpg file. Unable to do so. Can someone please help

Accepted Answer

Jackson Burns
Jackson Burns on 13 Oct 2019
Edited: Jackson Burns on 13 Oct 2019
Hi Joshua!
saveas needs a figure handle to save. assigning a to the output of plot gives you a line instead. Fix it with this:
% "Produce a single plot containing the horizontal displacement
% as a function of time from the recorded data"
x = 1:0.01:10;
y = x.^2;
z = x.^3;
a = figure;
plot(x,y,x,z)
xlabel('Time (seconds)')
ylabel('Horizontal displacement (m)')
title('Part 5')
legend('Attempt 1', 'Attempt 2')
saveas(a,'Plot 5.jpg')

More Answers (0)

Categories

Find more on Printing and Saving in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!