Using uifigure to show progress of script

조회 수: 3 (최근 30일)
Johannes
Johannes 2021년 4월 28일
답변: Johannes 2021년 4월 28일
Hi there,
I'm working on a rather complex and often time consuming script, and so far I inform myself of my progress in the old school way by fprintf('',x,y,z) the progress on my screen. But the command window becomes rather cluttered because of this, and for this + some other reasons I'd like it to simply be a dialogue box popping up at the top.
So here's what I've been doing:
The following is initialised before the while and for loops are initialised.
ui.prog.fig=uifigure('Name','Progress','HandleVisibility', 'on','WindowStyle','modal');
ui.prog.fig.Position(3:4)=[400 100];ui.prog.fig.Position(1:2)=[1 1080-ui.prog.fig.Position(4)-30];
ui.prog.lblrqp=uilabel(ui.prog.fig,'Text','Initiating','Position',[10 30 100 40],'FontSize',16);
ui.prog.lblrqp.Position(3)=ui.prog.fig.Position(3)-2*ui.prog.lblrqp.Position(1);
Then the while loops operate. These are terminated by the break command once the conditions are met. Towards of the end of the loops we thus have this:
ui.prog.lblrqp.Text=sprintf('%s %s Mode %d\nrqp=%d WL=%.4fs not identified: %d',strCOR{COR},strID{IDENT},MODE(mode),rqp,Lw,nonident);
My intention here being to update the text in the ui figure as long as this runs.
However, this hasn't really worked out. The uifigure seems to only pop up once all the loops have finalised, making all of this quite pointless.
Is there a workaround or is there a different type of dialogue box that can do this?
Note also that I assumed that closing and initialising a new window every time could be unnecessarily processing power consuming, hence why I tried to do it by just updating a label inside an existing figure.
Also I did the
'WindowStyle','modal'
hoping that the window would always be at the top, but whether I had it included or not had no effect as the window sadly wasn't created in the first place until too late.
  댓글 수: 2
Johannes
Johannes 2021년 4월 28일
I tested it out by adding a drawnow command after the text updating line, both with and without limitrate. The figure does now show earlier than before, but it doesn't update the text, so it's stuck at "Initialising".

댓글을 달려면 로그인하십시오.

채택된 답변

Johannes
Johannes 2021년 4월 28일
Ok I figured it out now, with help from Stephen Cobeldick, but he only provided the link and here's an in-depth explanation if anyone's interested: The solution is to add a drawnow limitrate command.
However, using "ui.prog.lblrqp.Text" (the part before ".Text" being the name given to the label) doesn't work, even with the drawnow. This one can't update it until after the whileloop is finished. Instead you have to reference the label directly. In my case: "ui.prog.fig.Children.Text". The part before ".Children.Text" being the name I gave to the figure.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by