Laz*_*zer 9 matlab plot intersection graph
我有这个情节
[ 全分辨率 ]

我需要在用户输入的 x轴上的一个点上做一条直线垂直线,并显示该垂直线与我的图的交点的坐标.
如何在MATLAB中完成?
例如:用户输入1020然后将在1020处绘制直线垂直线,其在某点处与绘图相遇并且将以某种方式显示该点的坐标.
一种方法是使用GINPUT功能以图形方式使用鼠标选择一个点.假设您绘制的数据存储在变量中data,以下代码应该执行您想要的那种操作.
set(gca,'XLimMode','manual','YLimMode','manual');  % Fix axes limits
hold on;
[x,y] = ginput(1);  % Select a point with the mouse
x = round(x);       % Round x to nearest integer value
y = data(x);        % Get y data of intersection
plot([x x],get(gca,'YLim'),'k--');  % Plot dashed line
plot(x,y,'r*');     % Mark intersection with red asterisk
disp('Intersection coordinates:');
disp([x y]);        % Display the intersection point
以上假设图表的x值只是您正在绘制的数据数组的索引,这可能是您在上面显示的图表中的情况.