changing time step of data or resample the data

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

sam moor
sam moor 2016년 11월 9일
please help me out this problem
Guillaume
Guillaume 2016년 11월 11일
additional information that was provided as an answer moved here - Guillaume
Here is my data image. 1st column is time and other columns are distance. What I see is the first column is non monotonic that means there are some values which are repeated e.g 1 and 110 rows of first column. so interp1 function is not working. I don't how to solve this repeated problem. I used unique function for column 1 but again the vectors are of different length. So let me know how to solve this problem. Thank you.
Jan
Jan 2016년 11월 11일
@sam: Please do not post screenshots. We cannot play with these data or try a suggested solution. Prefer posting data as text or as attached file. Thanks.
sam moor
sam moor 2016년 11월 12일
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 2016년 11월 12일
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

댓글을 달려면 로그인하십시오.

답변 (2개)

Jan
Jan 2016년 11월 10일
편집: Jan 2016년 11월 10일

2 개 추천

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

sam moor
sam moor 2016년 11월 10일
편집: sam moor 2016년 11월 10일
Thanks for your answer. But I need to change only 1st column i.e time step data should be 0.02 so that my 1st column data be 0.02 sec,0.04,0.06,0.08......60 sec(in my 1st column data I have time step of 0.1 up to 1 sec and then 0.001 time step up to 60 sec)With the change of 1st column in to uniform time step my other columns data should also change ( interpolate). So I don't think I need to do row in ascending order. Hope you understand my problem and waiting your response. I appreciate your answer. Thanks
sam moor
sam moor 2016년 11월 10일
when I try that code. It gives me error:
Error using griddedInterpolant The grid vectors are not strictly monotonic increasing.
That's why Jan told you to sort the column.
I don't understand your explanation of the time steps, shouldn't they be
[0.1 0.2 0.3 ... 0.9 1 1.0001 1.0002 .... 59.9999 60] .'
sam moor
sam moor 2016년 11월 10일
I mean my 1st column data should be 0.02,0.04,0.06....i.e difference of 0.02
Guillaume
Guillaume 2016년 11월 11일
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.

댓글을 달려면 로그인하십시오.

Guillaume
Guillaume 2016년 11월 10일

0 개 추천

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

sam moor
sam moor 2016년 11월 10일
편집: Guillaume 2016년 11월 11일
Here is my data image. 1st column is time and other columns are distance. What I see is the first column is non monotonic that means there are some values which are repeated e.g 1 and 110 rows of first column. so interp1 function is not working. I don't how to solve this repeated problem. I used unique function for column 1 but again the vectors are of different length. So let me know how to solve this problem. Thank you.
snipped duplicated images that are now as comment to the question - Guillaume
Guillaume
Guillaume 2016년 11월 11일
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 2016년 11월 12일
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.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Interpolation에 대해 자세히 알아보기

질문:

2016년 11월 9일

댓글:

2016년 11월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by