1
votes

I have created MatLab GUI and it execute matlab script by clicking button on GUI.

now I want method for showing time consuming for run of that script

following code shows how I did that so far

function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
run('resizeingDONTDELETE.m');
end 

I find a code for show wait bar but it is not worked!!!!

h = waitbar(0,'Please wait...');
steps = 1000;
for step = 1:steps
run('resizeingDONTDELETE.m');
    waitbar(step / steps)
end
close(h)

here I want the results as follow,

  • when push button is clicked wait button should be open and should show time as zero
  • time should be increased with time taken to executing the script
  • after executing wait bar should be disappered

can anyone help me .......

1
your waitbar call should be somewhere inside resizeingDONTDELETE.m, if it has a for loop, not outside.Itamar Katz
what happened it contain no of for loopsSahan Priyanga
how can it modify in order to display the prograss (I mean when half of script is executed then bar remain at it middle point and like wise)Sahan Priyanga
see my answer, it becomes too long for a commentItamar Katz

1 Answers

0
votes

A waitbar is useful if your script is divided to some intermediate steps (not necessarily a for loop), where you can indicate a progress in (or before) each intermediate step. In pseudo-code, assuming you have 4 intermediate steps:

  • Main Script
    • waitbar(0/4)
    • do intermediate step 1
    • waitbar(1/4)
    • do intermediate step 2
    • waitbar(2/4)
    • do intermediate step 3
    • waitbar(3/4)
    • do intermediate step 4
    • waitbar(4/4)

Otherwise, if your script is a 'black box' which starts and terminates without giving you access to some intermediate steps - you cannot use waitbar in a useful way.