You are taking two approaches simultaneously in your code. You create a plot where I suspsect you want to visualize the ships, but then you are populating a matrix with the values. In order for the ships to appear on your axes, you must plot them somehow (plot, scatter, line, etc).
If you want to display board instead, perhaps somethink like heatmap will work?
x2 = x1 + length(submarine) - 1;
board(x1:x2, y1) = submarine(1)
board =
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
31 0 0 0 0 0 0 0 0 0
31 0 0 0 0 0 0 0 0 0
31 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
letters = {'A';'B';'C';'D';'E';'F';'G';'H';'I';'J'};
set(gca,'XDisplayLabels',letters);
0 Comments
Sign in to comment.