Accessing ROI objects in GUIDE

3 views (last 30 days)
John D
John D on 22 Nov 2019
Commented: John D on 23 Nov 2019
I'm allowing the user to create a series of line ROIs like so, using a GUIDE app pushbutton:
function pushbuttonline_Callback(hObject, eventdata, handles)
% hObject handle to linebtn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
h = drawline(handles.axes1);
But how can I access these later on in the code?
I was thinking of placing the drawline variables in a global array, but is there a better way of doing this?
Also, if the user deleted a line using the GUI, would the line variable also be removed?
Thanks in advance.

Accepted Answer

Adam Danz
Adam Danz on 22 Nov 2019
Edited: Adam Danz on 22 Nov 2019
This demo works outside of your GUI callback but it will be easy to implement it into your GUI. See inline comments for details.
% Create axes (your gui will already have axes)
handles.axes1 = axes();
% Draw 3 lines (your gui will only have 1 of these lines
% but it's important to add the 'Tag' to your line.
% The tag name should be something unique - I chose 'userLine'.
h = drawline(handles.axes1,'Tag','userLine');
h = drawline(handles.axes1,'Tag','userLine');
h = drawline(handles.axes1,'Tag','userLine');
% Later on from any other callback function that has
% access to 'handles', you can find all objects in
% your axes that has that tag. If 'lineHandles' is
% empty, no objects were found with that tag. Otherwise
% 'lineHandles' will contain all of the handles to your
% ROI lines.
lineHandles = findobj(handles.axes1,'Tag','userLine')
  6 Comments
Adam Danz
Adam Danz on 23 Nov 2019
Edited: Adam Danz on 23 Nov 2019
Better yet,
ax = findobj(h.Parent,'Type','axes','Tag','axes1')
When using findobj() or findall() you want to be as specific as possible.

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Products


Release

R2019a

Community Treasure Hunt

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

Start Hunting!