How to manipulate a handle with a function
조회 수: 1 (최근 30일)
이전 댓글 표시
Dear all, I do not know exactly how to describe my problem, but maybe you know any help.
I have a GUI. In this GUI I have a Text which I want to manipulate during my calculations.
So what I do is, after klicking a Start-Button, I run a simulation in another function. This one takes a long time. Therefor I would like to give Status-Updates.
How it looks right now:
% --- Executes on button press in startOptimization.
function startOptimization_Callback(hObject, eventdata, handles)
% hObject handle to startOptimization (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
button_state = get(hObject,'Value');
if button_state == get(hObject,'Max')
% Toggle button is pressed-take appropriate action
switch get(handles.calcType.SelectedObject,'Tag') % Get Tag of selected object.
case 'carfixed'
.....
[x, handles.y, handles.z, ~, b] = optimizeTrips(item,lPinput,handles.c,1);
.... optimizeTrips is my function which now has a lot of "for"
function [hit, lT, kmD, ran, perc] = optimizeTrips(i,LP,f,ep)
for w=1:21
....
end
end
So I would like to update my handles.textStatus with every "w" but I don't know how to transfer this data from the one function to my GUI.
I appreciate any help. Even if you just tell me how to google that stuff :D
Thank you very much.
댓글 수: 0
채택된 답변
Geoff Hayes
2015년 10월 27일
Peter - why not just pass in the handle to the text control that you wish to update on each iteration of the outer for loop? The signature for your optimizeTrips would then become
function [hit, lT, kmD, ran, perc] = optimizeTrips(i,LP,f,ep,hTxtControl)
and your for loop would be something like
for w=1:21
set(hTxtControl,'String',num2str(w));
pause(0.5);
for ...
end
end
Note how we pause for half a second to allow the control to be updated with the new text (and, depending upon how quick your loops execute, gives the user a chance to see the changing iterations).
You would then call this function as
[x, handles.y, handles.z, ~, b] = optimizeTrips(item,lPinput,handles.c,1, handles.text1);
where handles.text1 is the handle to the text control that you wish to update.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!