How to plot point x on a line

70 ビュー (過去 30 日間)
Anonymous Learner
Anonymous Learner 2015 年 5 月 2 日
コメント済み: Anonymous Learner 2015 年 5 月 2 日
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

採用された回答

Nobel Mondal
Nobel Mondal 2015 年 5 月 2 日
編集済み: Nobel Mondal 2015 年 5 月 2 日
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;
  1 件のコメント
Anonymous Learner
Anonymous Learner 2015 年 5 月 2 日
thanks a lot for your help that's what i was looking for

サインインしてコメントする。

その他の回答 (1 件)

pfb
pfb 2015 年 5 月 2 日
編集済み: pfb 2015 年 5 月 2 日
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 件のコメント
Anonymous Learner
Anonymous Learner 2015 年 5 月 2 日
thanks for your help

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeGraphics Performance についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by