1

那么我面临的问题是非常基本的。我编写了以下代码将一条线分成 10 个部分并找到每个部分的坐标。程序运行良好,但输出文本文件未显示正确结果。我只想在文本文件的列中打印 linspace 的结果。谢谢。

h=input('enter the size of the test box ');
theta=input('the angle');
xs=input('enter the x1 position of the slipplane');
ys=input('enter the y1 position of the slipplane');

r=h/sind(theta);
xe=(xs+(h/sind(theta)));
ye=(ys+(h/sind(theta)));
x1=xs+4;
y1=ys+4;
x10=xe-4;
y10=ye-4;

   n=linspace(x1,x10,10)
   m=linspace(y1,y10,10)

fid = fopen('result.txt', 'wt'); 
fprintf(fid,' %f\t %f\n',n,m);
fclose(fid);
4

1 回答 1

1

采用:

h=input('enter the size of the test box ');
theta=input('the angle');
xs=input('enter the x1 position of the slipplane');
ys=input('enter the y1 position of the slipplane');

r=h/sind(theta);
xe=(xs+(h/sind(theta)));
ye=(ys+(h/sind(theta)));
x1=xs+4;
y1=ys+4;
x10=xe-4;
y10=ye-4;

   n=linspace(x1,x10,10)
   m=linspace(y1,y10,10)

fid = fopen('result.txt', 'wt'); 
fprintf(fid,'%f\t %f\n',[n;m]);
fclose(fid);

终端:

enter the size of the test box 10
the angle10
enter the x1 position of the slipplane10
enter the y1 position of the slipplane10

n =

  Columns 1 through 5

   14.0000   19.5097   25.0195   30.5292   36.0390

  Columns 6 through 10

   41.5487   47.0585   52.5682   58.0780   63.5877


m =

  Columns 1 through 5

   14.0000   19.5097   25.0195   30.5292   36.0390

  Columns 6 through 10

   41.5487   47.0585   52.5682   58.0780   63.5877

result.txt 的内容:

14.000000    14.000000
19.509745    19.509745
25.019490    25.019490
30.529235    30.529235
36.038980    36.038980
41.548725    41.548725
47.058470    47.058470
52.568215    52.568215
58.077960    58.077960
63.587705    63.587705
于 2013-03-20T05:47:01.057 回答