[問題]matlab畫五子棋棋子

看板MATLAB作者 (CLH)時間10年前 (2015/05/28 21:00), 編輯推噓2(202)
留言4則, 2人參與, 最新討論串1/1
最近在做程式語言期末專題,我選的主題是五子棋 不過我在畫棋子的的時候遇到一點困難 我先貼棋子的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://www.ptt.cc/bbs/MATLAB/M.1432818045.A.814.html

05/29 11:57, , 1F
會是沒有輸出嗎? f = chess(a, b)
05/29 11:57, 1F

05/29 15:03, , 2F
對,不會出現棋子,並出現error
05/29 15:03, 2F

05/29 22:08, , 3F
呃,我的意思是你在主程式裡並沒有給chess一個輸出的變
05/29 22:08, 3F

05/29 22:08, , 4F
數,不過這好像不影響…
05/29 22:08, 4F
文章代碼(AID): #1LPn5zWK (MATLAB)
文章代碼(AID): #1LPn5zWK (MATLAB)