changing time step of data or resample the data

13 Ansichten (letzte 30 Tage)
sam moor
sam moor am 9 Nov. 2016
Kommentiert: sam moor am 12 Nov. 2016
I have a motion data with different time step as shown in figure. 1st column represent time step and 2nd to 4th column represent motion. Now, My problem is I want to change the time step of motion data in to uniform time step, say 0.02 sec. How can I change my time step to 0.02 sec time step in matlab? Any answer are highly appreciated. Thank you.
  5 Kommentare
sam moor
sam moor am 12 Nov. 2016
Hi Jan, Here is my data. Is there any solution for this type of data we can change time step of 0.02. I have omitted repeated value but still giving me error that it is non-monotonic
sam moor
sam moor am 12 Nov. 2016
This is my new file data after I delete repeated values but still showing error when using interp1. Please help on this problem...your answer are highly appreciated.. thank you

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Jan
Jan am 10 Nov. 2016
Bearbeitet: Jan am 10 Nov. 2016
Sort the rows at first to get an ascending order. Then call interp1:
xx = 0.001:0.02:1.0;
yy = interp1(x, y, xx)
  5 Kommentare
sam moor
sam moor am 10 Nov. 2016
I mean my 1st column data should be 0.02,0.04,0.06....i.e difference of 0.02
Guillaume
Guillaume am 11 Nov. 2016
The problem is not with what it should be, it's not difficult to create that, the problem is with what it is now. Your input is not monotonous, so you need to decide what you want to do about it.

Melden Sie sich an, um zu kommentieren.


Guillaume
Guillaume am 10 Nov. 2016
If you're on R2016b, you could convert your matrix into a timetable, with for example
t = array2table(yourmatrix(:, 2:end), 'rowTimes', ...
datetime(0, 0, 0, 0, 0, yourmatrix(:, 1), 'Format', 'ss.SSS'));
The retime function has then plenty of options to resample your data over the interval and step you want, e.g.:
newtimes = datetime(0, 0, 0, 0, 0, 0) : duration(0, 0, 0.02) : datetime(0, 0, 0, 0, 0, 60);
newtimes.Format = 'ss.SS';
newt = retime(t, newtimes, 'linear');
However, the times in your original array need to be stricly monotonically increasing for any interpolation to work, so you will encounter the same issues as with Jan's answer.
The advantage of a timetable is that there are plenty of built-in function to resample values / aggregate them by period, etc.
  3 Kommentare
Guillaume
Guillaume am 11 Nov. 2016
Well, you need to decide what you want to do about your input and these duplicated values. Matlab can't do that for you.
You can indeed only keep one set with unique (but which one, the duplicates are vastly different) but really you need to work out why you have duplicates in the first place and what it means. You could also aggregate the values (average / median / etc.), again only can decide what is appropriate
Once you've worked out what to do, then it is trivial to use interp1 or retime.
sam moor
sam moor am 12 Nov. 2016
I have solved the repeated values data, nut still giving me the error when using interp1. I have attached my data file. please give me a solution to solve this.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Entering Commands finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by