Good day,
I have tried using Jan Simon's answer in How to use the mouse to select and identify a line on a plot
I am struggling to adapt this to a GUI I have built in GUIDE and have the following code in a callback:
handles.P(1) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk1);
handles.P(2) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk2);
handles.P(3) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk3);
The question is regarding the input arguments to LineSelected and the construction of the handles for the lines. Is handles.P(x) the correct way to create handles to the lines that belong to handles.Plot1?
function LineSelected(ObjectH, EventData, H)
set(ObjectH, 'LineWidth', 2.5);
set(H(H ~= ObjectH), 'LineWidth', 0.5);
If I am using a GUI built in GUIDE, are my input arguments for the function hObject, eventdata and handles? Then for ObjectH do I replace that with handles.P?
Cheers

 Réponse acceptée

Jan
Jan le 8 Jan 2018
Modifié(e) : Jan le 8 Jan 2018

0 votes

E.g.:
handles.P(1) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk1);
handles.P(2) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk2);
handles.P(3) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk3);
set(handles.P, 'ButtonDownFcn', {@LineSelected, handles.P});
...
function LineSelected(ObjectH, EventData, AllLines)
set(ObjectH, 'LineWidth', 2.5);
set(AllLines(AllLines ~= ObjectH), 'LineWidth', 0.5);
end
Or maybe easier:
function LineSelected(ObjectH, EventData, AllLines)
set(AllLines, 'LineWidth', 0.5);
set(ObjectH, 'LineWidth', 2.5);
end

5 commentaires

TJ
TJ le 8 Jan 2018
Thanks Jan. Just a quick question- Is the handles.P and additional argument in the function handle which then corresponds to the 'AllLines' in the function definition?
Jan
Jan le 9 Jan 2018
Modifié(e) : Jan le 9 Jan 2018
@TJ: Exactly. You could write also:
AllLines(1) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk1);
AllLines(2) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk2);
AllLines[3) = line(handles.Plot1, 'XData', chunktime, 'YData', normChunk3);
set(AllLines, 'ButtonDownFcn', {@LineSelected, AllLines});
TJ
TJ le 9 Jan 2018
I understand. Cheers Jan. Thanks a lot.
TJ
TJ le 9 Jan 2018
Sorry Jan, one more question. Not sure if you can answer but do you know where I should store the set function so that it only executes if I click on the lines in the graph in the GUI rather than the code sequentially always going through the set function as it is not in a call back. For example. The lines are plotted using a plot push button. Then the callback is completed. Then the user clicks on a line and the line should change width and then return a property for the GUI such as 'Tag'. I have just stored the line outside any callbacks but it will always execute even when I do not click on the graph.
Jan
Jan le 9 Jan 2018
@TJ: The question is not clear to me yet. The ButtonDownFcn callback does execute only, if you click on the line. Which code "goes through the set functions"? What do you want to return to the GUI? Where have you "stored the line" and how did you do this?
I assume posting the code will clarify what you are asking for. Maybe in a new thread?

Connectez-vous pour commenter.

Plus de réponses (2)

Tamir Suliman
Tamir Suliman le 8 Jan 2018

0 votes

you just need to follow this part of the example
H(2) = plot(1:10, rand(1, 10), 'b');
set(H, 'ButtonDownFcn', {@LineSelected, H})

2 commentaires

TJ
TJ le 8 Jan 2018
Hi Tamir,
The function handle surely implies that the LineSelected function should be defined in the code?
Walter Roberson
Walter Roberson le 8 Jan 2018
You can store the lines you gave in LineSelected.m

Connectez-vous pour commenter.

Tamir Suliman
Tamir Suliman le 8 Jan 2018

0 votes

so basically your handles variables or what ever action you assign to it would be the set function

Catégories

En savoir plus sur Creating, Deleting, and Querying Graphics Objects dans Centre d'aide et File Exchange

Question posée :

TJ
le 8 Jan 2018

Commenté :

Jan
le 9 Jan 2018

Community Treasure Hunt

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

Start Hunting!

Translated by