How to plot point x on a line
44 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Anonymous Learner
el 2 de Mayo de 2015
Comentada: Anonymous Learner
el 2 de Mayo de 2015
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
0 comentarios
Respuesta aceptada
Nobel Mondal
el 2 de Mayo de 2015
Editada: Nobel Mondal
el 2 de Mayo de 2015
I agree that the question is a bit unclear.
If you're wondering how to find and highlight the intersection point(s) between two curves this below code snippet might be helpful:
x1 = [1 2 3 4]; y1 = [0 2 4 6];
x2 = [1 2 3 4]; y2 = [6 4 2 0];
% find intersection
[x_intsect, y_intsect] = polyxpoly(x1, y1, x2, y2)
% plot everything on a single figure
figure;
hold on;
plot(x1, y1, 'k-', x2, y2, 'r-');
plot(x_intsect, y_intsect, 'bo');
hold off;
Más respuestas (1)
pfb
el 2 de Mayo de 2015
Editada: pfb
el 2 de Mayo de 2015
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,'.');
Ver también
Categorías
Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!