function gridbar(x,y,w)
% x is the data at x-axis
% y is the data at y-axis
% w is the width of bar
% Example:
% gridbar(1:6,rand(1,6),0.4);
for k=1:length(x);
xk=x(k);yk=y(k);
plot([xk-w,xk-w,xk+w,xk+w],[0,yk,yk,0],'k');
hold on;
end
xt=get(gca,'xtick');
yt=get(gca,'ytick');
Po=get(gca,'Position');
A=[yt(2)-yt(1)]/[xt(2)-xt(1)];
A=tan(A)*2;
yd=[xt(2)+w]*tan(A);
D=[yt(2)-yt(1)]/3;
xm=min(xt);ym=min(yt);
for k=1:length(x);
xk=x(k);yk=y(k);
ydt=-[xk+w]*tan(A)+D;
while ydt<[yk-(xk-w)*tan(A)];
xc=[ym-ydt]/tan(A);
if xc<xk+w & xc>xk-w;
x1=xc;y1=ym;
else
x1=xk-w;y1=(xk-w)*tan(A)+ydt;
end
xc=[yk-ydt]/tan(A);
if xc<xk+w & xc>xk-w;
x2=xc;y2=yk;
else
x
实现matlab直方图的网格填充
最新推荐文章于 2024-05-29 08:30:00 发布