zl程序教程

您现在的位置是:首页 >  后端

当前栏目

matlab画直线,指定斜率与x坐标范围

MATLAB 指定 范围 坐标 直线 斜率
2023-09-14 09:02:25 时间

闲话不说,直接上代码与图的效果!

 


AngleD=59; %[-90 90]
c=20:80;
centralPoint=[50 50]';
image=zeros(100,100);
image(25:74,25:74)=ceil(abs(rand(50,50).*10));


if abs(AngleD)==90,
    fprintf(1,'no single line for the x area\n');
elseif AngleD==0,
    r=centralPoint(1).*ones(size(c,2),1);
else
    k=tand(AngleD);
    b=centralPoint(1)-k*centralPoint(2);
    r=k.*c+b;
end

imagesc(image);
hold on
plot(c,r,'r-');
hold off;
colormap gray;
axis equal