MATLAB Answers

0

remove the blank area surrounding the figure

Asked by Jimmy Liang on 23 May 2019
Latest activity Commented on by Adam Danz
on 28 May 2019 at 13:29
My objective is to creat checkerboard and assign different values to white and black squares, the code is showed below. How can I I remove the blank area surrounding the figure, which means to enable the figure to fill the whole window. Thank you!!
K = checkerboard(500,1,1);
K(K>0)=1;
figure
imshow(K)
mask = K > 0;
K(mask) = 10;
K(~mask) = 100;

  0 Comments

Sign in to comment.

1 Answer

Answer by Adam Danz
on 23 May 2019
Edited by Adam Danz
on 24 May 2019
 Accepted Answer

"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); %make figure square
ax = axes('Units','Normalize','Position',[0 0 1 1]); %set axes to fill figure
K = checkerboard(500,1,1);
K(K>0)=1;
imshow(K,'Parent', ax) %specify axes

  3 Comments

You might also like to add these:
% Get rid of tool bar and pulldown menus that are along top of figure.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Give a name to the title bar.
set(gcf, 'Name', 'Checkerboard Demo', 'NumberTitle', 'Off')
thank you very much guys.
one more little question, because I have assigned values in the checkerboard, if I want to save these values when I save the checkerboard image, do I need particular code or command? or just save the image and the values will be inside?
How are you assigning values in the checkerboard? Where are those values stored? Whatever values are stored in the figure (or axes) properties will be retrievable if you save the figure and reopen it.

Sign in to comment.