How do I randomly extract 20 segments of data from a signal?
2 次查看(过去 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!