フィルターのクリア

pass string variable to a function in uicontrol callback

8 ビュー (過去 30 日間)
v k
v k 2020 年 10 月 22 日
コメント済み: v k 2020 年 10 月 25 日
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.

採用された回答

Stephen23
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 ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by