matlab 生成斜率为k,截距为b的直线

自己学习的过程中,个人备份代码。

%第一步  生成斜率为k,截距为b的直线,并在直线上截取十个点的坐标

 k=rand(1,1);
%k=randi([-100,100],1,1);
b=randi([-10000,10000],1,1);
x1=randi([-300000,300000],1,1);
x=x1:100:x1+900;
 y=k*x+b;


%第二步%直角坐标转换成极坐标
[theta,rho]=cart2pol(x,y);
%第三步 弧度转换成角度
theta1=theta*57.29578;
theta2=[];
for i=1:10
    if(theta1(i)>=0&&theta1(i)<=360)
        theta2(i)=theta1(i);
    else
        theta2(i)=theta1(i)+360;
    end
end

%I/0操作,输出的数据为txt文件
x=theta2
y=rho
fp=fopen('L10.txt','a');
format long g
fprintf(fp,'%0.4f \r\n',x);%注意:\r\n为换行(在系统为windows的情况下)。
fclose(fp);
fp=fopen('L11.txt','a');
 format long g
 fprintf(fp,'%0.4f \r\n',y);%注意:\r\n为换行(在系统为windows的情况下)。
fclose(fp);


猜你喜欢

转载自blog.csdn.net/Saber_lyl/article/details/80392916