2014 dxdy logo

Научный форум dxdy

Математика, Физика, Computer Science, Machine Learning, LaTeX, Механика и Техника, Химия,
Биология и Медицина, Экономика и Финансовая Математика, Гуманитарные науки




 
 Матлаб (попытка сделать игру)
Сообщение27.03.2015, 19:29 
Код:
function GUI
figure('MenuBar','None', ...
    'Name', 'Gui01', ...
    'NumberTitle','Off',...
    'Position',[500 500 500 500])
k=0;
for i=1:8
    for j=1:8
        k=k+1;
        A(i,j) = uicontrol('Style', 'ToggleButton',...
            'BackgroundColor', 'b',...
            'Position' , [50*i 50*j 50 50],...
            'Tag',int2str(k),...
            'string',int2str(k),...
            'CallBack',@PushButtonPressed);
    end
end


    function PushButtonPressed(h,eventdata)
       
       
        set(A(i,j), 'BackgroundColor','r')
    end
end

помогите сделать так, чтобы по нажатию на любую кнопку она окрашивалась в красный цвет,

 
 
 
 Re: Матлаб (попытка сделать игру)
Сообщение28.03.2015, 18:27 
Так будет окрашиваться в красный:
Код:
function GUI
figure('MenuBar','None', ...
    'Name', 'Gui01', ...
    'NumberTitle','Off',...
    'Position',[200 250 500 500])
k=0;
for i=1:8
    for j=1:8
        k=k+1;
        A(i,j) = uicontrol('Style', 'ToggleButton',...
            'BackgroundColor', 'b',...
            'Position' , [50*i 50*j 50 50],...
            'Tag',int2str(k),...
            'string',int2str(k),...
            'CallBack',@PushButtonPressed);
    end
end
end

function PushButtonPressed(h,eventdata)
set(h, 'BackgroundColor','r')
end

 
 
 [ Сообщений: 2 ] 


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group