Filter löschen
Filter löschen

problem of displaying the progress bar on a separate figure

3 Ansichten (letzte 30 Tage)
Samah EL QASSAH
Samah EL QASSAH am 20 Sep. 2017
Kommentiert: Rik am 20 Sep. 2017
Hi,
I created a GUI in which I insert a progress bar which starts when the output of my simulink subsystem goes to 1. The code is as follows:
I added the following lines to the OpeningFcn function:
% --- Executes just before MAJ is made visible.
function MAJ_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI_MAJ_Distance_OTA (see VARARGIN)
axes(handles.axes1);
set(handles.axes1,'Xtick',[],'Ytick',[],'Xlim',[0 1000]);
rectangle('Position',[0,0,(round(0))+1,20],'FaceColor','green', 'visible', 'off');
text(480,10,[num2str(0),'%']);
The code:
function Output_GUI(obj, event, handles)
rto1 = get_param('MAJ/X','RuntimeObject');
if((rto1.OutputPort(15).Data == 1) & (rto1.OutputPort(16).Data == 0))
set(handles.axes1, 'visible', 'on');
Max=1000; % Maximum value
set(handles.axes1,'Xtick',[],'Ytick',[],'Xlim',[0 1000]);
for Index = 0 : Max
axes(handles.axes1);
cla(handles.axes1);
rectangle('Position',[0,0,(round(1000*Index/Max))+1,20],'FaceColor','green');
text(480,10,[num2str(round(100*Index/Max)),'%']);
end
end
Once the output 16 is set to 1, the progression must reach 100%
I insert an axis on my HMI as shown here:
The problem is that the progress bar is displayed on a separate GUI and the progress is very slow.
I don't know what exactly the problem.

Akzeptierte Antwort

Rik
Rik am 20 Sep. 2017
Why go to the trouble of making something yourself when Matlab has a nice and ready solution for you: waitbar. It has been in Matlab for a very long time, so even backward compatibility isn't an issue (in case you'dd need that).

Weitere Antworten (1)

Samah EL QASSAH
Samah EL QASSAH am 20 Sep. 2017
I have the this code where Inputport is X and Outputport is Y
function Output_GUI(obj, event, handles)
rto1 = get_param('waitbar_test/Sub','RuntimeObject');
if((rto1.InputPort(1).Data == 1) & (rto1.OutputPort(1).Data ~= 1))
h = waitbar(0,'Please wait...');
steps = 10000;
for step = 1:steps
% computations take place here
waitbar(step / steps)
end
close(h)
end
When X = 1 the waitbar must start in parallel with the simulink counter. Once the timer finishes Y goes to 1 and the waitbar must reach 100%.
But that is not what happens. When X = 1 the waitbar starts and simulink is blocked so the counter does not progress anymore. The waitbar runs in a loop. and it is only when I close the waitbar that the counter starts counting.
I don't understand what the problem is.
  1 Kommentar
Rik
Rik am 20 Sep. 2017
You need to provide the handle to a waitbar to update the progress. Read the doc for more information about how to use it. I have next to no experience with Simulink, so I can't tell if there is anything you should be doing differently with that interface.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Dialog Boxes finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by