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 に答える