Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
ND
ND le 17 Fév 2017
Commenté : ND le 17 Fév 2017
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
ND
ND le 17 Fév 2017
Modifié(e) : ND le 17 Fév 2017
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 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?

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
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
  1 commentaire
ND
ND le 17 Fév 2017
Many thanks Walter for your help. Please it is possible to use for loop or you think this better?

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by