Send data to main gui after pushbutton
Show older comments
I have made a script that draw lines in a picture inside a gui. For each line it calculates its distance. Now I want to make a function that can delete some of the lines. The amount of lines is defined by "nlines"
What I have is a pushbutton that generates a new window with a checkbox for each created line and a delete_button. When pushing this button, the respecting lines have to be deleted and "nlines" have to be decreased. I do get the data inside of the pushbutton_deletebutton function. But cannot get the handles back into the main gui.
I have the following:
function ClearMeasuresButton_Callback(hObject, eventdata, handles)
% hObject handle to ClearMeasuresButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
nlines = handles.nlines; %Amount of lines
if nlines == 0
msgbox('There are no measures yet')
return
end
distance = handles.distance; %Distances of lines
fig = figure('Visible','off');
box = zeros(nlines,1);
txtbox = zeros(nlines,1);
panel = uipanel('parent',fig,...
'Title','Choose lines to delete',...
'position',[.01 .02 .95 .95]);
A=zeros(nlines,1);
label1 = uicontrol('parent',panel,'style','text',...
'Position',[20 nlines*25+60 150 30],...
'String',{'Choose the measurement';'you want to delete'});
for i = 1:nlines
f.box(i) = uicontrol('parent', panel,'style','checkbox', ...
'tag', sprintf('checkbox%d', i),...
'position',[20 nlines*25+60-i*25 40 20]);
txtbox = uicontrol('parent', panel,'Style','text',...
'String',[num2str(i), ' : ', num2str(Distance(i),3), ' [m]'],...
'Position',[40 nlines*25+60-i*25 100 20]);
end
handles.f = f;
deletebutton = uicontrol('Parent', panel, 'style', 'pushbutton',...
'tag', 'deletebutton','String', 'Delete',...
'callback', {@Pushbutton_deletebutton, handles},...
'position',[20 20 60 30]);
set(fig, 'Visible', 'on', 'Position',[1000 450-nlines*25 200 nlines*25+130]);
guidata(hObject,handles)
And the function for the Pushbutton that deletes the lines.
function handles = Pushbutton_deletebutton(hObject, eventdata, handles)
f = handles.f;
nlines = handles.nlines
distance = handles.distance
for k = 1:length(f.box)
val(k) = f.box(1,k).Value; %Values of the checkboxes
end
for j = length(val):-1:1
if val(j) == 1
distance(j) = [];
nlines = nlines-1;
end
end
handles.distance = distance;
handles.nlines = nlines;
guidata(hObject,handles)
2 Comments
Jan
on 17 Jun 2018
Just a remark: Simplification of the code:
% for k = 1:length(f.box)
% val(k) = f.box(1,k).Value; %Values of the checkboxes
% end
val = [f.box.Value];
% for j = length(val):-1:1
% if val(j) == 1
% distance(j) = [];
% nlines = nlines-1;
% end
% end
distance(val == 1) = [];
nlines = nlines - sum(val == 1);
Lars
on 18 Jun 2018
Accepted Answer
More Answers (0)
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!