필터 지우기
필터 지우기

How to use the mouse to select and identify a line on a plot

조회 수: 44 (최근 30일)
Andrew
Andrew 2013년 7월 26일
댓글: Jan 2022년 2월 25일
Hi,
I have an analysis that I am performing repeatedly. There are two multi-channel data sources. These sources have different and possibly varying identification numbers. It is important that data source A and B are correctly identified.
I would like to be able to include a user interactive check where a channel from source A and B are plotted together. The user is then asked for instance to pick or highlight the line from data set A. This is then used to identify A and B. If necessary a swap of data sets is then performed prior to launching into the full analysis.
I am new to GUI programming and using callbacks etc in Matlab and would appreciate any comments or suggestions on this.
Regards
Andrew Sims

답변 (2개)

Jan
Jan 2013년 7월 26일
편집: Jan 2013년 7월 26일
You can use the ButtonDownFcn of the line objects:
function smallTest
axes('NextPlot', 'add')
H(1) = plot(1:10, rand(1, 10), 'r');
H(2) = plot(1:10, rand(1, 10), 'b');
set(H, 'ButtonDownFcn', {@LineSelected, H})
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 2.5);
set(H(H ~= ObjectH), 'LineWidth', 0.5);
  댓글 수: 12
Claus Andersson
Claus Andersson 2022년 2월 24일
Jan, thanks for the very helpful solution above - is there a way to 'inline' this LineWidth change in the 'set' call to avoid having the function LineSelected.
I would like to have the figure stay interactive, even after the function has stopped running.
Jan
Jan 2022년 2월 24일
I do not understand, what you are asking for.
You need to write the code of a callback into a function. Where do you want to "inline" it instead?
The figure does stay interactive. Which function stopped running?

댓글을 달려면 로그인하십시오.


Claus Andersson
Claus Andersson 2022년 2월 24일
Hi Jan. My mistake. It works perfectly and the callback continues to work, I had a typo.

카테고리

Help CenterFile Exchange에서 Specifying 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