Why a variable randomly is not updated in MATLAB GUI using guidata function?

Hello, I have a problem in a GUI made using MATLAB Guide.
I have some timer functions which are executed sequentially. There is one variable (handles.UserData.C_cnt) which is shared between the timer functions. The variable is not updated after some random number of the execution of the timer function and I cannot figure out why this occurs. Could you check if the following structure I use for updating the variables inside a timer function is correct?
function timer_fcn(obj,event,hObject,eventdata)
handles = guidata(hObject);
handles.UserData.C_cnt = handles.UserData.C_cnt+1;
guidata(hObject, handles);

댓글 수: 3

That single piece of code looks fine. How it interacts with the rest of your code we don't know though. I can fairly certainly say there is nothing 'random' about it though. Undiscovered, perhaps, but it will be purely logical unless your program actually includes randomness.
RZM
RZM 2018년 9월 7일
편집: RZM 2018년 9월 7일
I agree. Some experts recommend not to use global variables and they are evil so I tried to avoid them in GUI. But here when I use global variables it works fine so in this case I call them angels. :D I have also used eval function which is not recommended, maybe this random problem came from that but I had no other choice.
@RZM: please upload your code by clicking the paperclip button.

답변 (0개)

이 질문은 마감되었습니다.

제품

릴리스

R2018a

태그

질문:

RZM
2018년 9월 7일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by