MATLAB: Write a function drawBox which draws boxes on the screen

homeworkMATLABmatlab function

I got a task but I am confused. This is My task The function is called with a character (ch) as the first argument and two positive integers which represent the width and the height of the box to be drawn. It automatically draws a box with the character (ch) by the specified width and height. Can Anyone help me out with the task.

Best Answer

function drawBox(str,w,h)
ch = [0. 0.] ;
%%get four corners of box
N = 20 ;
x = linspace(ch(1),ch(1)+w,N) ;
y = linspace(ch(2),ch(2)+h,N) ;
[X,Y] = meshgrid(x,y) ;
X(2:end-1,2:end-1) = NaN ;
Y(2:end-1,2:end-1) = NaN ;
x = X(~isnan(X)) ;y = Y(~isnan(Y)) ;
plot(x,y,'.w') ; hold on
text(x,y,str)
axis off