Read Text files, subtract the columns of the text file and same in same text file.

9 visualizaciones (últimos 30 días)
Hi everyone,
How do i read multiple text files, subtract column 2 from 5, column 3 from 6, column 4 from 7 and write the the output in same file to column 8, 9 and 10 respectively.

Respuestas (1)

Voss
Voss el 16 de Dic. de 2021
You can use readmatrix to read the file.
To do the arithmetic and storing the result in the same matrix, you can do something like this:
data = randn(100,7); % I'm making up some random data here. Your data will come from your text file.
data(:,[8 9 10]) = data(:,[5 6 7]) - data(:,[2 3 4]); % do column 5 minus column 2, store result in column 8, etc.
Then use writematrix to write the variable data to the same file you read.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by