Effacer les filtres
Effacer les filtres

Expanding array from seconds to samples

2 vues (au cours des 30 derniers jours)
Anna Kasdan
Anna Kasdan le 3 Avr 2018
Commenté : Anna Kasdan le 4 Avr 2018
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.

Réponse acceptée

David Fletcher
David Fletcher le 3 Avr 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
  1 commentaire
Anna Kasdan
Anna Kasdan le 4 Avr 2018
thank you! And yes, the code does not run slower.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Feature Detection and Extraction dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by