Please how can I edit/expand data of a text file in Matlab?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Walter Roberson
le 17 Fév 2017
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?
Réponse acceptée
Walter Roberson
le 17 Fév 2017
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Plot Customization dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!