MATLAB Answers

Excecute App Designer ValueChangeFcn Callback function programmitically

67 views (last 30 days)
Jibran Shahid
Jibran Shahid on 8 Jan 2018
Answered: Jibran Shahid on 8 Jan 2018
Hello fellow members, Previously I have made several GUIs programmatically with GUIDE components. Recently I am developing the GUI using App designer Components. In GUIDE components, it was easy to execute callback functions programmatically.I am trying the same method for App Designer components but it is not working.
I have one uiedittext field, I have changed its value programmitically and now I want to execute its callback function aka ValueChangedFcn, but I haven't able to figure out the way to mimic it.
I would be very thankful if anybody can help me in this matter. FYI I am using MATLAB 2017a

  0 Comments

Sign in to comment.

Answers (1)

Jibran Shahid
Jibran Shahid on 8 Jan 2018
Hello again fellow members, well after playing for an hour. I finally figured it out, but instead of deleting the question. I thought why not just post an answer. So here is my solution.
txt = uieditfield(fig,...
'Position',[100 175 100 22],...
'tag','texteditField',...
'ValueChangedFcn',@(txt,event) textChanged(txt,lbl));
end
% Code the callback function.
function textChanged(txt,lbl)
lbl.Text = txt.Value;
end
In the above code, if I want to find this graphical object from any other funtion then I can use findobj with the current figure as a first argument of findobj.
Txt = findobj(figure,'tag','texteditField')
TxtCallback = Txt.ValueChangedFcn;
TxtCallback(Txt);
Thank you

  0 Comments

Sign in to comment.

Sign in to answer this question.