How do I randomly extract 20 segments of data from a signal?
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a matrix of data 60001x4. Rows are data points, columns are the 4 channels recording the data. How would I extract 20 random samples of 1000 data points from each channel? Goal would be to have a 20x1 cell array where each cell is a 1000x4 matrix representing 1 1000-sample segment across the 4 channels. I have done this so far but there must be a better way to do this to make it truly random segments. I simply divided the duration of my signal by 1000 to get how many (num_segments) I would end up with. Then i used randperm to generate 20 random numbers that would correspond to each segment of the 20 out of 60 segments, in this case, that I want.
random_indices = randperm(num_segments,20);
0 commentaires
Réponse acceptée
Star Strider
le 18 Août 2021
If I understand correctrly what you want to do, this could work:
signal = randn(60001,4)
random_indices = randperm(size(signal,1)-1000, 20)
rowidx = [random_indices(:) random_indices(:)+999]
for k = 1:numel(random_indices)
RandomSamples{k,:} = signal(rowidx(k,1):rowidx(k,2),:);
end
RandomSamples
Some of the samples would necessarilly overlap.
.
0 commentaires
Plus de réponses (1)
David Hill
le 18 Août 2021
You could just keep matrix form with a 3rd dimension
for k=1:20
newMatrix(:,:,k)=yourMatrix(randperm(60001,1000),:);
end
Voir également
Catégories
En savoir plus sur Random Number Generation 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!