编写一个在matlab中在屏幕上绘制框的功能

时间:2016-12-03 14:39:29

标签: matlab

调用该函数时,字符(ch)作为第一个参数,两个正整数表示要绘制的框的宽度和高度。它会自动使用指定的宽度和高度绘制一个带有字符(ch)的框。enter image description here

1 个答案:

答案 0 :(得分:0)

检查是否有效:

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

来源:https://in.mathworks.com/matlabcentral/answers/314681-write-a-function-drawbox-which-draws-boxes-on-the-screen