Creating a linear plot over a plot of giving numbers

2 views (last 30 days)
Currently I am having trouble trying to plot a function. Im trying to create 4 different subplots but I need this one line to be on it for comparison. So for the first sub plot i would have
x1= [10; 8; 13; 9; 11; 14; 6; 4; 12; 7; 5;]
y1= [8.04; 6.95; 7.58; 8.81; 8.33; 9.96; 7.24; 4.26; 10.84; 4.82; 5.68;]
subplot(2,2,1)
hold on
plot (x1,y1)
now with this i need to plot the line y=3+0.5x over a range 0 to 20. So far every attempt i have made has not worked.

Answers (1)

Star Strider
Star Strider on 16 Feb 2019
Try this:
plot (x1,y1,'p')
hold on
plot([0 20], 3+0.5*[0 20])
hold off
It’s a linear function, so you only need the limits, not all the intermediate independent data.

Tags

Community Treasure Hunt

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

Start Hunting!