3 つのボタンとテキスト ボックスで図を作成するコードを作成しました。ただし、ボタンを押すと、プログラムはコールバック関数について不平を言います。
function game(states)
fig=figure('position',[200 150 500 370]);
face.B1=uicontrol('parent',fig,'style','pushbutton','string','start!','visible','on','position',[20 160 460 50]);
face.B2=uicontrol('style','pushbutton','parent',fig,'string','B2','visible','off','position',[20 90 460 50]);
face.B3=uicontrol('style','pushbutton','parent',fig,'string','B3','visible','off','position',[20 20 460 50]);
face.txtbx=uicontrol('style','text','parent',fig,'string','welcome to my game. press start to begin','position',[20 230 460 120]);
%set the callback function of the button
%when the button is pressed, i want to initiate the changestate function
set(face.B1,'callback','changestate(face,states,1);');
% while 1
uiwait(fig)
% end
end
これは、ボタンが押されたときに呼び出したい関数です。この関数の内容は私の質問にとって重要ではありませんが、念のため含めます
function face = changestate(face,states,nextstate)
disp('enter changestate')
face.B1=set(face.B1,'string',states{nextstate}.B1str,'callback','changestate(face,states,states{nextstate}.B1next)');
if ~isnan(states(nextstate).B2str)
face.B2=set(face.B2,'string',states{nextstate}.B2str,'callback','changestate(face,states,states{nextstate}.B2next)','visible','on');
else face.B2=set(face.B2,'visible','off');
end
if ~isnan(states(nextstate).B3str)
face.B3=set(face.B3,'string',states{nextstate}.B3str,'callback','changestate(face,states,states{nextstate}.B3next)','visible','on');
else face.B3=set(face.B3,'visible','off');
end
face.txtbx=set(face.txtbx,'string',states{nextstate}.txtbxstr);
% uiresume(fig)
end
私が受け取っているエラーは次のとおりです。
waitfor 未定義の関数または変数 'face' の使用中にエラーが発生しました。
waitfor 使用エラー uicontrol コールバックの評価中にエラーが発生しました
このエラーは、ボタン B1 を押したときに発生します。ボタンで changestate 関数を開始したい。誰かが私にこのエラーが発生する理由を説明できますか?