Expanding array from seconds to samples

조회 수: 1 (최근 30일)
Anna Kasdan
Anna Kasdan 2018년 4월 3일
댓글: Anna Kasdan 2018년 4월 4일
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.

채택된 답변

David Fletcher
David Fletcher 2018년 4월 3일
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
  댓글 수: 1
Anna Kasdan
Anna Kasdan 2018년 4월 4일
thank you! And yes, the code does not run slower.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by