Adding rows to matrix conditionally
2 ビュー (過去 30 日間)
I have long datafiles that I need to alter and cannot figure out how to do this.
The simplified version of what I'm trying to do is:
x = 1 20
Column 1 is time (t) (sec 1, 3, 6) and col 2 the values.
I want to create a new matrix with time axis with 1 sec interval and that the values (col 2) are repeated until next (t) ( in col1)
The resulting matrix should be:
x2 = 1 20
Sorry about the elementery question, I'm a newby
Star Strider 2020 年 3 月 31 日
I will defer to Guillaume’s Answer, since he posted the solution first. The data file is attached.
Guillaume 2020 年 3 月 31 日
We don't have enough details to give you a complete answer but what you want to do should be easily done by
- reading your file as a timetable. Could be as easy as:
data = readtimetable(yourfile);
depending on the actual file
- retime the timetable to 1 second interval, which is simply:
resampled = retime(data, 'secondly', 'previous'); %retime in one second interval using the previously known value for the missing times
- save into a new file
その他の回答 (1 件)
Andrei Bobrov 2020 年 3 月 31 日
out = [(x(1,1):x(end,1))',repelem(x(:,2),[diff(x(:,1));1])];
Find more on Timetables 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!