Trace variables of a function when executing

3 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2022-9-11
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 个评论
SAM Arani
SAM Arani 2022-9-11
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 2022-9-11
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by