Drawing a tangent line on plot but keep getting the error "array indices must be positive integers or logical values"?
1 view (last 30 days)
Show older comments
I have a plot and I picked two points from that plot that I need to use to draw a tangent line.
After choosing the points, I used them to find the slope and then changed it to slope intercept form to find the y value. Then I plotted it.
Here is my code:
%original plot
plot(X1,Y1)
%picking points
x1=3.4959;
y1=1925.72;
x=14.214;
y=8113.27;
%slope formula
k=(y-y1)/(x-x1);
y=k(x-x1)+y1; %this is the line giving me the error
hold on
plot(x,y);
hold off
Why doesn't this work? I was told to compute the slope and then use y-y1=k(x-x1) to draw the line. What did I do wrong?
0 Comments
Answers (1)
See Also
Categories
Find more on Annotations 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!