Clear Filters
Clear Filters

Trace variables of a function when executing

3 views (last 30 days)
I have a matlab UI and it is desired to update the progressbar of this UI based on a variable which is being used in a running code ina function.
Consider below example:
%% a UI Code:
currentProg = min(round((size(wbar,2)-2)*(i/n)),size(wbar,2)-2);
RGB = app.processDataButtonHandle.Icon;
RGB(2:end-1, 2:currentProg+1, 1) = 0.25391; % (royalblue)
RGB(2:end-1, 2:currentProg+1, 2) = 0.41016;
RGB(2:end-1, 2:currentProg+1, 3) = 0.87891;
app.processDataButtonHandle.Icon = RGB; % (royalblue)
where
i
is a variable which shall be real time value of iterations in a for loop used in a function.
So, the whole code can be seen as:
%% a UI Code:
currentProg = min(round((size(wbar,2)-2)*(i/n)),size(wbar,2)-2);
RGB = app.processDataButtonHandle.Icon;
RGB(2:end-1, 2:currentProg+1, 1) = 0.25391; % (royalblue)
RGB(2:end-1, 2:currentProg+1, 2) = 0.41016;
RGB(2:end-1, 2:currentProg+1, 3) = 0.87891;
app.processDataButtonHandle.Icon = RGB; % (royalblue)
my_function(m,n,...)% other input variables
where in my_function() we have:
function my_function(m,n,...)% other input variables
for i=1:n
%% do some thing based on m
end
end
Do we have any possible way of updating that progress bar based on variable i which is in a for loop inside a function?

Accepted Answer

Walter Roberson
Walter Roberson on 11 Sep 2022
No, not without the cooperation of the function being executed or using the debug facilities, or the cooperation of some function called by the target function
  2 Comments
SAM Arani
SAM Arani on 11 Sep 2022
can I have examples of introduced ways?
I'm not so sure about the ways you mentioned but the debug facilities.
What do you mean by cooperation of the funtion or the functions called by the target function?
Walter Roberson
Walter Roberson on 11 Sep 2022
The function itself could call waitbar(). Or a function that it calls could call waitbar(). Or you could use "dbstop at LINE if CONDITION" where you have coded CONDITION to invoke something that calls waitbar()
Note: there is an enhanced function that works like waitbar in the File Exchange, that also shows an estimate of time to completion

Sign in to comment.

More Answers (0)

Categories

Find more on Dialog Boxes in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!