Expanding array from seconds to samples

1 view (last 30 days)
I have an array (these are seconds of EEG data) that I want to expand to samples, where Fs=128.
bad_seconds = [1 2 11 13 14 15 17 18 22 24 26 27 37 47 48 50 57 58 70 75 90 118 120 144 145 147]
So for example, I would want the first two elements of the array to expand by 128 and look like this
bad_samples = [1:256 1208:1408.....]
I tried something like the following, but it doesn't get me the range that I want, just the start and end values and I would ideally just insert a colon between every other value for the range of samples!
Fs = 128;
bad_samples_start = (bad_seconds * Fs)-128;
bad_samples_end = bad_samples_start + 128;
temp = [bad_samples_start; bad_samples_end];
combined = temp(:)';
Any help would be appreciated, thanks! Still learning my way around Matlab things.

Accepted Answer

David Fletcher
David Fletcher on 3 Apr 2018
Something like this?
bad_seconds = [1 2 11 13 14 15 17 18 22 24 26 27 37 47 48 50 57 58 70 75 90 118 120 144 145 147]
t1=bad_seconds*128-128;
t2=t1+127;
ranges=[t1;t2]
combined=[]
for iter=1:size(ranges,2)
combined=[combined ranges(1,iter):ranges(2,iter)];
end
A few things to note: The combined array is grown dynamically. This is generally frowned upon, but unless this section of code becomes noticeably slow, I wouldn't worry about it.
I've slightly amended the formula for the range end point as there was an overlap between consecutive ranges. I was also slightly unsure whether you wanted the start of the range to be one more than defined by your formula (bad_seconds*128-127 rather than bad_seconds*128-128), but I've left that as per your formula

More Answers (0)

Community Treasure Hunt

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

Start Hunting!