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.

采纳的回答

Geoff Hayes
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by