# if we enter n rows and m colums and gets the output of 2n rows and 2m columns

12 views (last 30 days)
Answered: Himanshu Gabhane on 4 Jun 2020
Write a function named blocks that takes two positive integers, n and m, as input arguments (the function does not have to check the format of the input) and returns one matrix as an output argument. The function needs to return a 2n-by-2m matrix where the upper right and lower left n-by m sub matrices are all zeros and the rest of the matrix are all ones.
Patricio Mosquera on 26 Aug 2016
Just choose your n and m
A = [1 0 ; 0 1];
B = ones([n, m]);
out = kron(A,B);

Andrei Bobrov on 27 Jun 2013
Edited: Andrei Bobrov on 27 Jun 2013
##### 2 CommentsShowHide 1 older comment
Andrei Bobrov on 4 Jul 2013
n = 5;
m = 3;
out = zeros([n m]*2);
for jj = 1:2
out((jj-1)*n+(1:n),(jj-1)*m+(1:m)) = 1;
end

ANAMIKA YADAV on 15 Oct 2019
function out=blocks(n,m);
out=zeros([n m]*2);
out(3:4,1:3)=1;
out(1:2,4:6)=1;

Himanshu Gabhane on 4 Jun 2020
function out=blocks(n,m)
out=zeros([n m]*2);
out(end/2+1:end,1:end/2)=1;
out(1:end/2,end/2+1:end)=1;
end