Time elapsed for running a GUI program
Show older comments
Hi, I have designed a GUI code which takes various input and gives various output.My function is 'MasterIO'(refer the code below).Now I want to know the total time elapsed to run 'MasterIO' and want to display the same to the user.
% --- Executes on button press in StartButton.
function StartButton_Callback(hObject, eventdata, handles)
% hObject handle to StartButton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
clear var
%Optimization Method Selector data
% 1=No Optimization ;2=GA;3=AL;4=GSA
OMS = get(get(handles.OMS,'SelectedObject'),'UserData');
%GA mode 1=Fitness proportionate 2=roulette wheel
GAmode = get(handles.GAMode,'Value');
%Plant Selector data
% 1=FO;2=SO;3=RP
PLSE = get(get(handles.PLSE,'SelectedObject'),'UserData');
%Delay Selector data
% 0.0;0.1;0.2;0.3
Delay = get(get(handles.Delay,'SelectedObject'),'UserData');
%Mode Selec between PI & PID
% 1 = PI & 2=PID
Mode = get(get(handles.Mode,'SelectedObject'),'UserData');
Popsize = str2double(get(handles.Popsize,'string'));
MaxIteration = str2double(get(handles.MaxIteration,'string'));
NoOfVar = str2double(get(handles.NoOfVar,'string'));
Setpoint = str2double(get(handles.Setpoint,'string'));
ub = str2num(get(handles.ub,'string'));
lb = str2num(get(handles.lb,'string'));
% Transfering I/P Data to function
[BestPosition,BestResult,Response,History]=MasterIO(Popsize,MaxIteration,NoOfVar,...
ub,lb,Mode,PLSE,Delay,Setpoint,OMS,GAmode,handles);
Gcu = round(BestPosition(1),3);
Ge = round(BestPosition(2),3);
Gce = round(BestPosition(3),3);
if Mode == 2
Gu =round(BestPosition(4),3);
end
drawnow;
%Output Panel Data
set(handles.Gcu,'String',num2str(Gcu));
set(handles.Ge,'String',num2str(Ge));
set(handles.Gce,'String',num2str(Gce));
if Mode==2
set(handles.Gu,'String',num2str(Gu));
end
BestResult = round(BestResult,3);
set(handles.ITAE1,'String',num2str(BestResult));
%Plot Mode
set(handles.Status,'String','Done')
Please provide me the necessary code! Thanks in advance!
2 Comments
Jan
on 17 Apr 2017
Do you see that posting the code does not help to understand the problem? You could simplify the question to: "How do I measure and display the time needed to process a command?"
Sarit Hati
on 17 Apr 2017
Answers (1)
tic;
[BestPosition,BestResult,Response,History] = MasterIO(Popsize,MaxIteration,NoOfVar,...
ub,lb,Mode,PLSE,Delay,Setpoint,OMS,GAmode,handles);
elapsed = toc;
fprintf('Elapsed time: %.2f sec\n', elapsed);
Categories
Find more on Solver Outputs and Iterative Display 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!