How do I randomly extract 20 segments of data from a signal?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
Star Strider
2021년 8월 18일
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
추가 답변 (1개)
David Hill
2021년 8월 18일
You could just keep matrix form with a 3rd dimension
for k=1:20
newMatrix(:,:,k)=yourMatrix(randperm(60001,1000),:);
end
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!