How do I randomly extract 20 segments of data from a signal?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Anas Khan
am 18 Aug. 2021
Kommentiert: Anas Khan
am 19 Aug. 2021
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 Kommentare
Akzeptierte Antwort
Star Strider
am 18 Aug. 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 Kommentare
Weitere Antworten (1)
David Hill
am 18 Aug. 2021
You could just keep matrix form with a 3rd dimension
for k=1:20
newMatrix(:,:,k)=yourMatrix(randperm(60001,1000),:);
end
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!