打印结果的awk问题

时间:2013-03-20 04:11:37

标签: matlab output printf

我面临的问题是非常基本的。我编写了以下代码,将一行分成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);

1 个答案:

答案 0 :(得分: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