Change values of the first column in a txt file

2 views (last 30 days)
Hello everybody,
I am a student I don´t know very much about Matlab (I am sorry).
I have a file txt formed by two column (the first column is time in ms and the second some coordinates), as follow:
0.0000, -0.019
0.0010, -0.018
0.0020, -0.013
0.0030, -0.000
0.0040, 0.019
0.0050, 0.030
0.0060, 0.016
0.0070, 0.029
0.0080, -0.004
0.0090, -0.005
0.0100, -0.007
I combined 100 files txt (each file is a recording of 300000 milliseconds (5minutes)),
but the first column is repating always from 0 to 299999 (milliseconds)
I have to change the values of the first colum in the combined txt file without affecting the second one.
The first column has to be formed by the values from 0 to 30000000.
Could anyone help me with this issue?
This will help me with my research.
Thank you very much.
I really appreciate

Accepted Answer

Star Strider
Star Strider on 6 Dec 2021
It depends on the desired result in the combined file.
If they are supposed to be sequential (so that the first cxolumn in the first file ends at 299999 and the first column in the second file starts at 300000 I would just combine (vertically concatenate) all the second column values and re-define the first column using linspace to create a uniform time vector for the new first column.
If they are all supposed to share the same (0:2999999) time, horizontally concatenate only the second column of files 2 through 100 to the original file data.
Then, save the combined file to a new file name.
.
  2 Comments
Anton Yo
Anton Yo on 6 Dec 2021
@Star StriderThe concatenated txt file is like this:
0.0000, -0.019 from the firt file
0.0010, -0.018
........ ......
299999, -0.002
0.0000, 0.0015 from the second file
0.0080, -0.004
........ .........
299999, -0.007
......... .........
and so on
So I have to add the concatenated file in Matlab and use the linspace function to change the firt column? To write the number from 0 to 30000000 should I write a for cicle?
Thank you very much for replaying me.
Star Strider
Star Strider on 6 Dec 2021
To read and process the files, see: Import or Export a Sequence of Files .
I would so something like this for the time vector —
n = 100; % Number Of Files
Ts = 1E-3; % Sampling Interval
t = linspace(0, 300000*n-1, 300000*n).'*Ts; % Create Time Vector, Transpose To Column Vector
format long
Check = t(1:5) % Check Time Instants To Be Certain 't' Is As Desired
Check = 5×1
0 0.001000000000000 0.002000000000000 0.003000000000000 0.004000000000000
The ‘-1’ adjustment to the second argument, ‘300000*n-1’ ensures that the time intervals are as exact as possible.
.

Sign in to comment.

More Answers (0)

Categories

Find more on Interactive Control and Callbacks in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!