I have a large txt data and I got it with textread function. Inside the data a column is time stamp in microseconds. It is iterative rather cumulative. it looks like below:
I need to find the absolute seconds such as 57.987878. I managed to program it to find seconds but I could not add the seconds in front of microsesonds. Can somebody help me?
Hi seyasar, welcome to Octave discourse group!
I guess you want to separate seconds and microseconds, for that you only need to consider that a second is 10^6 microseconds.
a = 57.987878 a_seconds = floor(a); a_microseconds = 1e6*(a - a_seconds); fprintf("time: %d seconds and %.1f microseconds\n",a_seconds,a_microseconds);
time: 57 seconds and 987878.0 microseconds
Can you clarify what you meant by
but I could not add the seconds in front of microsesonds.
Can you add a sample of the desired output (calculated manually) for the first 5 lines of the input ?
Hi there, thank you very much for welcome and reply.
I mean the problem is that I don’t have 57.98787. I only have microseconds from 0 to 1.000.000. But at total I have 57 seconds, that means I have 57 times 0 to 1.000.000. I have to show them as normal timestamp as 57.987878.
Hi thank you for the response.
for the first second it is present from 0.9 to 1 (actual data is like 954578 ms I transfromed it to 0.954578)
for the other seconds I nedd e.g. 1.01 to 1.99 but it is again shown as 0.01 to 0.99.
Actual data (in seconds):
What I desire:
I think what you’re looking for is cumsum function
vector = 1:9; cumsum(vector)
1 3 6 10 15 21 28 36 45
Not really. I dont need a cumulative sum. I need to add seconds in front of decimals.
It wolud probably help to see more than one column if you have other relevant data in those columns.
by my incomplete understandnig, for some reason you have the following situation:
REALTIME YOURDATA 1.023456 0.023456 1.123585 0.123585 1.123988 0.123988 1.124564 0.124564 2.004561 0.004561 2.123456 0.123456 ...
Is that correct? is the whole-number second recorded anywhere? Are you just asking how to combine those two columns to get back to the real time? Or is that information not at all recorded? (and that alone is a problem you should probably seek to fix on the data acquisition side).
In any case, if the latter, can you guarantee that there are timesteps in every second, and that you will always have a negative ‘delta’ when it crosses into a new whole number second? e.g., the following becomes ambiguous
REALTIME YOURDATA 1.023456 0.023456 1.123585 0.123585 2.223585 0.223585
if you can be certain that won’t happen, then a counter and
diff could probably be used to calculate what the whole second value should be, and then append that to the microsecond data.
need some more clarity.
Yeah, some variation of
cumsum([0; (diff(tt)<0)]) + tt (where
tt is a column vector with the fractional part of your seconds) is probably what you could use.
This is just a “phase unwrapping” problem. “unwrap” from signal package might be helpful.
the seconds are not recorded additionally somewhere. First I have to count seconds which I did with findpeaks function with locations. but adding the corresponding second to the corresponding microsecond, I could not do it yet.
Yes it can be useful, I will try it.
Thanks a lot now I got the answer. SOLVED