Please how can I edit/expand data of a text file in Matlab?

2 次查看(过去 30 天)
I have a text file with two columns (x1,x2) I do need to expand the data according to the following equations:
x = (x1 + x2)/2 + ((x1-x2)/2)*cos(2Ө) , Ө = -30 :30
y = (x1 + x2)/2 - ((x1-x2)/2)*cos(2Ө) , Ө = -30 :30
xy = ((x1-x2)/2)*sin(2Ө) , Ө = -30 :30
The result would be a new text file has three expanded columns (x,y,xy).
Thanks
  6 个评论
ND
ND 2017-2-17
编辑:ND 2017-2-17
Sorry, I meant something different. I have text file with two columns one for x1 and second for x2 with many rows as the attached file. I need to calculate the values according to the above equations and write their output in a new file. I think I need to use for loop for (Ө) from -30 to 30 for each value of x1 and x2. Note that the original and output text files do not have any labels just numbers Many thanks for all help.
Walter Roberson
Walter Roberson 2017-2-17
Do you want 61 rows of results for the first row of the file, and the 61 rows of results for the second row of the file, and so on?
Or do you want the results for the entire input file for angle -30, and then the results for the entire input file for angle -29, and so on?

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2017-2-17
x1x2 = load('p.txt');
ang = -30:30;
nang = length(ang);
X1 = repmat(x1x2(:,1), 1, nang);
X2 = repmat(x1x2(:,2), 1, nang);
ANG = repmat(ang, size(x1x2,1), 1);
X = (X1 + X2)/2 + ((X1 - X2)/2) .* cosd(2*ANG);
Y = (X1 + X2)/2 - ((X1 - X2)/2) .* cosd(2*ANG);
XY = ((X1 - X2)/2) *. sind(2 * ANG);
x = X(:);
y = Y(:);
xy = XY(:);
xyxy = [x, y, xy];
dlmwrite('output.txt', xyxy, ' '); %space as delimiter
  1 个评论
ND
ND 2017-2-17
Many thanks Walter for your help. Please it is possible to use for loop or you think this better?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Plot Customization 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by