function s = e11v1(m) % s = e11v1(m): return a $m$-by-$2m$ string matrix $s$ with % + $*$s on the border (left, right, top, and bottom edges) % + $\$s on the diagonal, except for on the border % (the *diagonal* of a matrix = all valid positions (i,i) in the matrix) % + $-$s below the diagonal, except for on the border % + $+$s on the boundary, $@$s in the interior, and $c$ at the center of % a disk of radius $round(m*.35)$ and center $(round(m*1.5),round(m/2))$ % % concise version using trick of logical arrays and coordinate matrices n = 2*m; % width of $s$ % [3/14] fixed typo below, where $xc<-->yc$ xc = round(m*1.5); yc = round(m/2); % (yc,xc) = center of disk r = round(m*.35); % radius of disk % $x$, $y$: very useful for vectorization bonus, but probably no help otherwise y = repmat((1:m)', 1, n); % y(i,j) = i = the row position (i,j) is in x = repmat(1:n, m, 1); % x(i,j) = j = the col position (i,j) is in s(m,n) = ' '; % make $s$ large enough s(:,:) = 'o'; % fill each element with $'o'$ s(x < y) = '-'; % place $-$s below diagonal s(x == y) = '\'; % place $\$s on diagonal s([1 end],:) = '*'; s(:,[1 end]) = '*'; % place $*$s on border d = sqrt((x-xc).^2 + (y-yc).^2); % distances to center of disk s(d < r) = '@'; % place $@$s inside disk s(abs(d-r)<.5) = '+'; % place $+$s on disk s(yc, xc) = 'c'; % place $c$ at center of disk