Adding rows to matrix conditionally
이전 댓글 표시
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
3 50
6 10
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
2 20
3 50
4 50
5 50
6 10
Sorry about the elementery question, I'm a newby
댓글 수: 1
Star Strider
2020년 3월 31일
I will defer to Guillaume’s Answer, since he posted the solution first. The data file is attached.
채택된 답변
추가 답변 (1개)
Andrei Bobrov
2020년 3월 31일
out = [(x(1,1):x(end,1))',repelem(x(:,2),[diff(x(:,1));1])];
카테고리
도움말 센터 및 File Exchange에서 Timetables에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
