Borrar filtros
Borrar filtros

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

2 visualizaciones (últimos 30 días)
ND
ND el 17 de Feb. de 2017
Comentada: ND el 17 de Feb. de 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 comentarios
ND
ND el 17 de Feb. de 2017
Editada: ND el 17 de Feb. de 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 el 17 de Feb. de 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?

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 17 de Feb. de 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 comentario
ND
ND el 17 de Feb. de 2017
Many thanks Walter for your help. Please it is possible to use for loop or you think this better?

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Plot Customization en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by