MATLAB: GUI (static text display question)

drawnowguistatic text

percentage_complete=(1-(mxn-i)/mxn)*100;
if percentage_complete > 0 && percentage_complete < 25
set(handles.sonar_sali ent_percentage,'string','0')
elseif percentage_complete> 25 && percentage_complete < 50
set(handles.sonar_salient_percentage,'string','25')
elseif percentage_complete > 50 && percentage_complete < 75
set(handles.sonar_salient_percentage,'string','50')
elseif percentage_complete > 75 && percentage_complete < 100
set(handles.sonar_salient_percentage, 'string','75')
else
set(handles.sonar_salient_percentage,'string','100')
end
_________
Sorry not familiar with matlab coding.
I am trying to use static text in matlab GUI. i changed the tag to sonar_salient_percentage
and I want the static text to change in the GUI once a condition is met.
Right now the static text is not even updating? any idea what to do.
I am trying to display the percentage of completeness so i know when the code will finish running.

Best Answer

You have a space in this line:
set(handles.sonar_sali ent_percentage,'string','0')
but the main problem is that this is in a loop where things are probably changing so fast that the GUI doesn't get a chance to update/repaint/refresh. To force it to do that, put this line after your if block:
drawnow;
That will force it to change the static text immediately. If it were me, I'd do this:
percentage_complete = (1-(mxn-i)/mxn)*100;
caption = sprintf('Percent done = %.1f %%', percentage_complete);
set(handles.sonar_salient_percentage, 'String', caption);
drawnow;