Adding data
2 views (last 30 days)
Show older comments
Hello,
I have data in the following format:
00 08 255 267 298 300 - time[s]
5 4 3 4 3 2 - values
Time is given in seconds. The values in between stay the same, by this I mean that from 0s to 08s the value is 5 and then it changes to 4. I'd like to create a table (time vs. values) where each second has assigned a value. Something like this:
00 01 02 03 04 05 06 07 08 09 .....
5 5 5 5 5 5 5 5 4 4 .....
Any help is appreciated.
Thanks in advance
0 Comments
Accepted Answer
Jan
on 11 Nov 2011
t = [0, 8, 255, 267, 298, 300];
x = [5, 4, 3, 4, 3, 2];
index = zeros(1, t(end) + 1);
index(t + 1) = 1;
index = cumsum(index);
y = x(index);
3 Comments
Walter Roberson
on 11 Nov 2011
fprintf('%10g ', index);
fprintf('\n');
fprintf('%10g ', y);
fprintf('\n');
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays 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!