How can I fill a matrix in certain places with intervals?
1 view (last 30 days)
Show older comments
Hi.
I need to make a matrix that resembles a chessboard, however the number of pixels and how many squares are going to be decided by the user. So far I've managed to do just that:
N = input('How many squares ')
L = input('How many pixels ')
tab = ones(L*N,L*N);
k = 1;
for i=1:N^2
if mod(i,2) ~= 0
tab(i:L,i:L) = 0;
end
I can only "draw" the first square. How can I do the others? I know it's a silly question but I'm new in MATLAB.
0 Comments
Answers (1)
KALYAN ACHARJYA
on 29 Feb 2020
Edited: KALYAN ACHARJYA
on 29 Feb 2020
N=input('How many squares: ');
tab=ones(N,N);
tab(1:2:N,2:2:N)=0;
tab(2:2:N,1:2:N)=0;
imshow(logical(tab));
See Also
Categories
Find more on Operators and Elementary Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!