MATLAB: How can i draw rectangle in gui axes??

draw rectangle in gui

What wrong with the following???

Best Answer

Try specifying the parent axes in advance with axes():
axes(handles.layoutAxes);
rectangle('Position', [X_coordinate(i), Y_coordinate(i), 2, hdend(n, 1)]);