MATLAB Answers

0

Creating a linear plot over a plot of giving numbers

Asked by Benjamin Shuey on 16 Feb 2019
Latest activity Answered by Star Strider
on 16 Feb 2019
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.

  0 Comments

Sign in to comment.

Tags

1 Answer

Answer by 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.

  0 Comments

Sign in to comment.