【问题标题】:Matlab uicontrol function modificationmatlab uicontrol函数修改
【发布时间】:2014-06-04 09:37:42
【问题描述】:

我正在进行一个项目,其中某些部分与井字游戏有关。我有 tictactoe.m 文件并想更改代码,以便玩家的选择将通过函数的输出应用,例如,RESULT 参数,而不是用户自己点击屏幕。我的代码的 uicontrol 部分如下。如何通过另一个函数的输出而不是按钮样式来控制游戏?

function B = buttons
% Initialize push buttons and text.
clf
shg
B = zeros(3,3);
M = magic(3); % strategical approach and equivalent game for TicTacToe game.
for k = 1:9
[i,j] = find(k == M);
B(i,j) = uicontrol('style','pushbutton','units','normal', ...
  'fontsize',16,'callback','tictactoe(''green'')');
end
uicontrol('style','text','units','normal','pos',[0.30 0.82 0.40 0.10], ...
'fontsize',20,'background',get(gcf,'color'),'tag','toptext');

uicontrol('style','text','units','normal','pos',[0.20 0.72 0.60 0.10], ...
'fontsize',10,'background',get(gcf,'color'),'tag','toptext','string', ...
['Pick single digit numbers.  Each digit can be chosen only once. ' ...
'Generate a total of 15 using exactly three digits.'])

uicontrol('style','pushbutton','units','normal','string','Game', ...
'fontsize',12,'position',[.23 .12 .15 .07], ...
'callback','tictactoe(''game'')');

uicontrol('style','pushbutton','units','normal','string','Start', ...
'fontsize',12,'position',[.43 .12 .15 .07], ...
'callback','tictactoe(''start'')');

uicontrol('style','pushbutton','units','normal','string','Exit', ...
'fontsize',12,'position',[.63 .12 .15 .07], ...
'callback','tictactoe(''exit'')');

【问题讨论】:

    标签: matlab user-interface


    【解决方案1】:

    按钮所做的只是执行一个回调命令。在这种情况下,按钮“开始”正在调用

    tictactoe('start')
    

    所以你可以通过调用相同的函数来启动另一个函数,你将不得不查看函数“tictactoe”,因为它需要另外几个输入,按钮 uicontrol 会自动添加额外的输入,对象把手等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多