개발자 뺚

[Cody] Problem 55220. Matrix Quadrants 본문

Solution/MATLAB

[Cody] Problem 55220. Matrix Quadrants

2023. 11. 18. 15:00
Write a function that takes N as the input, and outputs a matrix whose upper-left (NxN) quadrant contains all ones, the lower-right (NxN) quadrant contains all N's, and zeros everywhere else. For example, if N = 3:
 


function M = foursquare(N)

    M = zeros(2 * N);
    M(1:N, 1:N) = ones(N);
    M(N + 1:2 * N, N + 1:2 * N) = N * ones(N);
end