作者clh960524 (CLH)
看板MATLAB
标题[问题]matlab画五子棋棋子
时间Thu May 28 21:00:42 2015
最近在做程式语言期末专题,我选的主题是五子棋
不过我在画棋子的的时候遇到一点困难
我先贴棋子的code:
function f = chess(color, action)
% CHESS.M
% to draw chess
%color = 1;
switch(action)
case 'start'
set(gcf, 'WindowButtonDownFcn', 'chess down');
case 'down'
set(gcf, 'WindowButtonUpFcn', 'chess up');
[x, y] = ginput(1);
%circle(0.125, x, y);
t = linspace(0, 2*pi, 100);
x1 = 0.125 * cos(t) + x;
y1 = 0.125 * sin(t) + y;
hold on;
plot(x1, y1);
if color == 1
fill (x1, y1, 'r');
color = 0;
elseif color == 0
fill(x1, y1, 'b');
color = 1;
end
case 'up'
set(gcf, 'WindowButtonUpFcn', 'chess start');
fprintf('Mouse up!\n');
otherwise
disp('Error');
% draw circle
end
这个function的目的是画出棋子,并交替画出红、蓝、红、蓝...
然後我再上棋盘的code:
clc
grid on
axis([-1.75 1.75 -1.75 1.75])
set(gca,'GridLineStyle','-','XTick',[-1.75:0.25:1.75],'YTick',[-1.75:0.25:1.75])
axis square
color = 1;
chess(color, 'start');
现在问题来了
当我画出棋盘的之後
我去点任意座标时
会出现以下的error:
Error using chess (line 8)
Not enough input arguments.
Error while evaluating figure WindowButtonDownFcn
请问大大们,我到底出错在哪?不是'start'之後会call自己吗?为甚麽会说"not enough
input arguments"?请问修正方式?
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 140.115.213.4
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MATLAB/M.1432818045.A.814.html
1F:推 physbook: 会是没有输出吗? f = chess(a, b) 05/29 11:57
2F:→ clh960524: 对,不会出现棋子,并出现error 05/29 15:03
3F:推 physbook: 呃,我的意思是你在主程式里并没有给chess一个输出的变 05/29 22:08
4F:→ physbook: 数,不过这好像不影响… 05/29 22:08