2013-03-20 5 views
1

Ну проблема, с которой я столкнулся, очень элементарно. Я написал следующий код, чтобы разделить строку на 10 частей и найти координаты каждой части. Программа работает нормально, но выходной текстовый файл не показывает правильный результат. Я просто хочу напечатать результат linspace в столбцах в текстовом файле. Благодарю.awk проблема с печатью результата

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); 
+0

@ kl3755 Но первые пять строк повторяется, не знаю, почему –

+0

@ kl3755 нужна помощь –

ответ

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 
Смежные вопросы