Borrar filtros
Borrar filtros

Can I add new column (calculated from first column) to a text file ?

1 visualización (últimos 30 días)
Dear all, Please I have a text file has one column and many rows. I need to add new column which is calculated from the first column (the difference between the new set of rows and old set of rows which means the change in the first column. for example, the set of rows below consists from three rows each ( the first zeros should be for both columns).I need to apply this for the text file attached.
0 0
0 0
0 0
1 (1-0)
3 (3-0)
6 (6-0)
2 (2-1)
5 (5-3)
8 (8-6)
Many thanks

Respuesta aceptada

Star Strider
Star Strider el 24 de Feb. de 2016
This seems to do what you want:
B = load('ND B.txt', '-ascii');
New_Col = [B(4:end) - B(1:end-3); zeros(3,1)];
New_B = [B New_Col];
The last 3 rows of ‘New_Column’ I set to zero to make it possible to concatenate it with the existing ‘B’. You may want to append them to the beginning instead, or set them to NaN. The point is the columns have to have equal length to concatenate them.
  8 comentarios
ND
ND el 5 de Mzo. de 2016
Editada: ND el 5 de Mzo. de 2016
Please now I want to do summation of column one and two (which is created) and write the column one and the sum in a new text file , so the result would be a text file with only two columns.
Thanks
Star Strider
Star Strider el 5 de Mzo. de 2016
This is actually a new Question and should be posted as such.
Also, please give an example of what you want to do. Your description is not clear.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices 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