pass string variable to a function in uicontrol callback
12 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a function which draws push-buttons and calls back another function. But it must pass the following three variables to the callback function:
function drawPushButtons(num1,randomVector,string1)
hCorrectAns=uicontrol(gcf,...
'Style','push',...
'Units','normalized', 'Position',[0.6 0 0.3 0.15],...
'FontName','Arial Unicode MS', 'FontSize',12,...
'String','Correct Answer',...
'CallBack',@correctAnswer);
end
Then, the callback function executes a code :
function correctAnswer(hCorrectAns, EventData)
for iAns=1:num1
%use randomVector to manipulate the variable 'string1'.
%There is uicontrol in this function also.
end
end
Unfortunately, even after trying various MATLAB Answers related to this type of query, the problem remains. How to pass these three variables from the uicontrol pushbutton to external callback function?
P.S. - declaring global is not an option. Thanks.
0 个评论
采纳的回答
Stephen23
2020-10-22
编辑:Stephen23
2020-10-22
Define the function to accept five input arguments:
function correctAnswer(hCorrectAns,EventData,num1,randomVector,string1)
and provide the extra arguments by specifying the callback inside a cell vector:
'CallBack',{@correctAnswer,num1,randomVector,string1}
This approach is documented here:
(Of course the names used inside the function are irrelevant to what they are named outside the callback)
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!