Change values of the first column in a txt file
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
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
Star Strider
on 6 Dec 2021
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
The ‘-1’ adjustment to the second argument, ‘300000*n-1’ ensures that the time intervals are as exact as possible.
.
More Answers (0)
See Also
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!