Why MATLAB App is standstill, collapse, when a video is executed and processed?

Why when execute a MATLAB App with different functions it collapse, saturate, standstill?
I think it is because the internal app variables (app.variable).
I would like to auto-respond my question with the next example.
I create an app which, given a video object (you can obtain it by: videoObject = VideoReader(video_rute)), execute a frame to frame:
When you click pause, the video stops.
The execution button have a loop that show every frame for every step, working correctly.
app.aturar_rep = false;
for frame = 1:app.video_obj_v.NumFrames
imgFrame = read(app.video_obj_v, frame);
app.Image.ImageSource = imgFrame;
if app.aturar_rep % to stop
break
end
end
Then, if we put an internal variable to re-define while executing the loop, the program collapse, and makes it go slower.
Here the example is in the variable app.dades_app
app.aturar_rep = false;
var_intern = [];
for frame = 1:app.video_obj_v.NumFrames
imgFrame = read(app.video_obj_v, frame);
app.Image.ImageSource = imgFrame;
if app.aturar_rep
break
end
for n = 1:100
app.dades_app = [app.dades_app, string(n)];
end
end
I show you, even in the first frame the program collapse:
And I need to Ctrl+C to re- run it.
Then, if we use a non-internal variable, this does not occurs (variable var_intern) :
app.aturar_rep = false;
var_intern = [];
for frame = 1:app.video_obj_v.NumFrames
imgFrame = read(app.video_obj_v, frame);
app.Image.ImageSource = imgFrame;
if app.aturar_rep
break
end
for n = 1:100
var_intern = [var_intern, string(n)];
end
end
I show you:
Then we have identifyied the standstill reason of MATLAB App, which mainly is the use of the App internal variables (app.variable_ex) (which are useful, but in this case dificult us).
Thank you!

3 Comments

Also, when calling app. variables, there is no lag. In example, in the loop:
for n = 1:100
var_intern = [var_intern, string(n)];
% Proba: crida a variables
var_Josep = app.video_obj_v;
dades_Josep = app.dades_app;
atura_Josep = app.aturar_rep;
video_obje_proba = app.video_obj_v;
end
The result:
But, when is changing the 'app.' variables, it makes delay:
for n = 1:100
var_intern = [var_intern, string(n)];
% Proba: crida a variables
var_Josep = app.video_obj_v;
app.dades_app = rand(1);
app.aturar_rep = rand(1);
end
As example:
Then the best option is not use the app. as changing variables, but yes as calling non-modificable ones.
When I have no idea about app. variables, I defined all the variables in internal spaces of the app, for example in Labels and TextAreas:
Other option is define the variables in .txt files, which are a fast a reliable way.
Cheers
Same time, if we generate the change of a internal object, there is no delay unless we change it too much fast
Code exampel:
for n = 1:100
var_intern = [var_intern, string(n)];
randomstr = [string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10))), string(char(randi([33 126],1,10)))];
end
app.ListBox.Items = randomstr;
If we generate a Axis changing, is the same, it will standstill in order of our upgrade.
for n = 1:100
var_intern = [var_intern, string(n)];
end
xline(app.UIAxes, [rand(1)], "Color", "c")

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!