Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

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

Asked by jawad on 27 Jun 2013

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.

0 Comments

jawad

Products

No products are associated with this question.

1 Answer

Answer by Andrei Bobrov on 27 Jun 2013
Edited by Andrei Bobrov on 27 Jun 2013
Accepted answer

Please read about MATLAB functions: ones and blkdiag.

2 Comments

jawad on 27 Jun 2013

Dear Andrei Bobrov My name is Jawad Durrani and I am doing MS in electrical communication. I have completed my course work and doing research now a days. I am learning Matlab for my research. I am studying the book "Computer Programming with Matlab by Michael Fitzpatrick and Akos Ledeczi" This is not my homework. Its one of the exercise problem. I already done by using built in function zeros and ones But i want to do it without using built in functions I hope you understand. Regards

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
Andrei Bobrov

Contact us