MATLAB Answers

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

12 views (last 30 days)
jawad on 27 Jun 2013
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.

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 27 Jun 2013
Edited: Andrei Bobrov on 27 Jun 2013
Please read about MATLAB functions: ones and blkdiag.
Andrei Bobrov
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;

Sign in to comment.

More Answers (2)

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

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!