Close a waitbar of a GUI from a function
이전 댓글 표시
Hello all,
I made a waitbar with a cancel button that appears when I press a push button on my GUI. This same push button makes another function runs. From inside this function I update the status of the waitbar.
My question is, if I press the cancel of the waitbar I want the function to stop running, and the user will be back to the main GUI.
This is the callback of the push button, indutancia is the function:
% --- Executes on button press in simular.
function simular_Callback(hObject, eventdata, handles)
% hObject handle to simular (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles.f = waitbar(0,'Aguardando inicialização...','Name','Aguarde por favor...',...
'CreateCancelBtn','setappdata(gcbf,''canceling'',1)');
setappdata(handles.f,'canceling',0);
indutancia(handles, hObject);
delete(handles.f);
Inside the function, there are lots of for loops.
The code below shows the loops where I update the waitbar. The problem is, when I press the Cancel button, the whole code freezes, and the waitbar continues there.
num_ind_inv = length(vetor_2n_inv);
for k = 1 : num_ind_inv
L_inv = 1e3 * vetor_2n_inv{k}(3); % [mH]
Fsw = vetor_2n_inv{k}(2);
Delta_i = vetor_2n_inv{k}(1);
for material = 1 : 5
proj_indutor(Fsw, L_inv, V, Pout, Vdc, material, Delta_i, I_out_p, I_out_ef);
prog_aux = prog_aux + 1;
prog = prog + prog_aux / total;
if getappdata(f,'canceling')
break
end
waitbar(prog,f,sprintf('%i de %i', prog_aux,total));
end
end
[...]
num_ind_ret = length(vetor_3n_ret);
for k = 1 : num_ind_ret
L_ret = 1e3 * vetor_3n_ret{k}(3); % [mH]
Fsw = vetor_3n_ret{k}(2);
Delta_i = vetor_3n_ret{k}(1);
for material = 1 : 5
proj_indutor(Fsw, L_ret, V, Pout, Vdc, material, Delta_i, I_in_p, I_in_ef);
prog_aux = prog_aux + 1;
prog = prog + prog_aux / total;
if getappdata(f,'canceling')
break
end
waitbar(prog,f,'Aguarde por favor...');
end
end
Thank you for the help!
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!