It is possible to run a script when you put a courson on a graph?

1 回表示 (過去 30 日間)
Jessie Bessel
Jessie Bessel 2022 年 6 月 8 日
編集済み: Jessie Bessel 2022 年 6 月 15 日
Hello.
Let's suppose that I have the graph from The figure 1 which represent the ratio of the sum of 5 paires of vectors.
I want the following thing to happen. When I put a coursor on one of the spikes, I want to automatically run a script and plot the two vectores that i considered for the ratio, as in Figure2.
It is possible this thing or is too futuristic?
Thanks a lot!

採用された回答

Jan
Jan 2022 年 6 月 8 日
Of course this works. It depends on what exactly "put a coursor" means. Moving the mouse over the obejct? Clicking on the line? Set a label?
All three possibilities can trigger a callback function. Please explain, what you exactly need.
I recommend not to run a script, but a function.
  2 件のコメント
Jessie Bessel
Jessie Bessel 2022 年 6 月 9 日
Thank you for the answer.
I want to click on a spike and then trigger a script or function or anything. I just want that the "click on the spike in the figure" be similar to a pushbutton. Can you tell me how to approach this problem?
Thank you a lot!
Jan
Jan 2022 年 6 月 9 日
編集済み: Jan 2022 年 6 月 9 日
How are the spikes shown? Are they different objects, e.g. of the type 'line'. Then use their ButtonDownFcn to catch the click:
figure;
axes('NextPlot', 'add', 'XLim', [0, 3], 'YLim', [0, 3])
line([1, 1], [0, 2], 'Color', rand(1, 3), 'ButtonDownFcn', @CB)
line([2, 2], [0, 2], 'Color', rand(1, 3), 'ButtonDownFcn', @CB)
function CB(LineH, EventData)
disp('You have clicked on me!')
LineH.LineWidth = LineH.LineWidth + 1;
LineH.Color = rand(1, 3);
end
Insert the code to create the diagrams in the callback function.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpecifying Target for Graphics Output についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by