Problems with Matlab Projects? You may face many Problems, but do not worry we are ready to solve your Problems. All you need to do is just leave your Comments. We will assure you that you will find a solution to your project along with future tips. On Request we will Mail you Matlab Codes for Registered Members of this site only, at free service...Follow Me.

Create Checkerboard using matlab


     I came across the matlab built in function checkerboard. And I tried to implement my own code.
First I declared the size of each square and then the number of rows and columns. Then I declared two matrixes initialized with zeros and ones. Using mod 2 I changed the colors or ones and zeros alternatively.
MATLAB CODE:
%Size of the square
sz=45;
%Number of rows
xvalue=8;
%Number of columns
yvalue=8;
%Intialize matrix A with zeros and matrix B with ones
A=zeros([sz sz]);
B=ones([sz sz]);
clear C
 m=sz;
 n=1;
 num=2;
for i=1:xvalue
    n1=1;
    m1=sz;
   
    for j=1:yvalue
        if(mod(num,2)==0)
        C(n:m,n1:m1)=A;
        num=num+1;
        else
        C(n:m,n1:m1)=B;
        num=num+1;
        end
       
        m1=m1+sz;
        n1=n1+sz;
    end
    if(mod(yvalue,2)==0)
    num=num+1;
    end
    n=n+sz;
    m=m+sz;
end
imshow(C)

8X8 size:45

8X20 size:15

0 comments:

Post a Comment

Recent Comments

Popular Matlab Topics

Share your knowledge - help others

Crazy over Matlab Projects ? - Join Now - Follow Me

Sites U Missed to Visit ?

Related Posts Plugin for WordPress, Blogger...

Latest Articles

Special Search For Matlab Projects

MATLAB PROJECTS

counter

Bharadwaj. Powered by Blogger.