How to plot point x on a line
Mostrar comentarios más antiguos
i am new in matlab i want to highlight point intersection point on a line in graph i can plot a point but not able to plot the point on line my code is here:
function[ x y]= test (x1,y1,x2,y2)
y=((-x1)+y1*(y2-y1))/(x2-x1);
x=((-y1*(x1-x2))/(y1-y2))+x1;
plot(x,y,'ro')
end
Respuesta aceptada
Más respuestas (1)
Not sure what you are asking, nor what your function is expected to do.
I guess x1,x2,y1,y2 are scalars (otherwise you're likely to get an error).
Your function calculates x and y based on those inputs, and plots it in a graph (by the way, since x and y are outputs, you can plot them outside your function).
Unless you get some sort of error, that should work.
Perhaps you are complaining that, after plotting a line, your function seems to delete it and plot only the point at (x,y).
If this is the case, you just need to hold the plots.
Matlab replaces the old plot with the new one, if you do not hold. After plotting the first line, write
hold;
or
hold on;
Take a look at the documentation of hold by typing "doc hold" in the command window.
A concrete example
% plot first line through points (0,1), (1,0)
plot([0 1],[1 0],'r');
% hold it
hold;
% plot second line through points (0,0.2) (1,1.2)
plot([0 1],[0.2 1.2],'r');
% plot a point at their intersection
plot(0.4,0.6,'.');
1 comentario
Anonymous Learner
el 2 de Mayo de 2015
Categorías
Más información sobre Line Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!