"How can I I remove the blank area surrounding the figure, which means to enable the figure to fill the whole window"
If you're refering to the figure window, here's a solution.
fh = figure();
fh.Position(3) = fh.Position(4);
ax = axes('Units','Normalize','Position',[0 0 1 1]);
K = checkerboard(500,1,1);