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 个评论
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
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Plot Customization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!