필터 지우기
필터 지우기

how can I plot a game board in a figure

조회 수: 7 (최근 30일)
Tariq Hammoudeh
Tariq Hammoudeh 2021년 12월 19일
댓글: Walter Roberson 2021년 12월 23일
Im programming the game battleship, and i need create a figure 2, 6 by 6 boards (one for the user and one for the computer). I was searching up on figures in matlab but i didnt find anything on how to create a grid in the figure. So how can i do that please, also can i have each grid correspond to a number from 1 to 36.

채택된 답변

Image Analyst
Image Analyst 2021년 12월 19일
You can just do
numSpaces = 6;
myBoard = zeros(numSpaces+1,numSpaces+1);
computersBoard = zeros(numSpaces+1,numSpaces+1);
subplot(1, 2, 1);
pcolor(myBoard);
axis square
title('Your Board', 'FontSize', 15)
subplot(1, 2, 2);
pcolor(computersBoard);
axis square
title('Computer Board', 'FontSize', 15)
Check the File Exchange, and click the tag on the left for numerous battleship programs:
  댓글 수: 30
Image Analyst
Image Analyst 2021년 12월 23일
Yes I agree that image() would be better than pcolor(). The only disadvantage is that image() doesn't give grid lines while pcolor() does. However you can use yline() and xline() to draw grid lines. If you do that then image is probably better because with pcolor you need to have one more row and column of your matrix that you basically don't use because pcolor() does not display the last row and column of the matrix.
Walter Roberson
Walter Roberson 2021년 12월 23일
pcolor() interpolates; which is a problem for this purpose.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by