Question

Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered that takes
0 0
Add a comment Improve this question Transcribed image text
Answer #1

---------------------------------------------------------------------------------------------------------------

(a) % Code below

function matrx = makeLayered(n)
%   
% make a matrix of (2*n-1)x(2*n-1)
matrx = ones(2*n-1,2*n-1);
if( n > 1)
% recursively call makeLayered(n-1)
mat = makeLayered(n-1);
% fill the first row, last row, first column and last column
% with n
for i=1:2*n-1
matrx(1,i) = n;
matrx(i,1) = n;
matrx(2*n-1,i) = n;
matrx(i,2*n-1) = n;
end
for i=2:2*n-2
for j=2:2*n-2
matrx(i,j) = mat(i-1,j-1);
end
end
end
  
end

---------------------------------------------------------------------------------------------------------------

(b) Screenshots of test cases :-

(i) For n = 1

= makeLayered (1) >>m 1(ii) For n = 3makeLayered (3) >>m m = 3 3 3 2 2 3 3 1 2 3 3 2 2 2 3 3 3 3 N N CO(iii) For n = 8

(8) makeLayered >>m m = 8 8 8 8 8 8 7 7 7 7 7 7 6 6 6 6 8 5 5 6 7 4 4 4 4 4 4 4 6 7 7 6 4 3 3 3 3 4 7 8 7 6 3 2 2 4 6 2 5 6 7

---------------------------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Question 9 Problem Solving, Design, Implementation and Testing in MATLAB (a) Create a function called makeLayered t...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT