How can I identify a vector subset that meets a given condition?

2 次查看(过去 30 天)
Given a vector A (please, see attached), how could I find the n-samples vector subset with the smallest range (or standard deviation)?
I am trying a potential solution: reshaping the vector in columns, performing range of each column and selecting the smallest. However, reshape does not always works well when applied to other examples with different lengths. How could this be worked around in an easier and more efficient way?
Fs = 1000; % sampling frequency
time = round(length(A)/Fs)-1; % calculate approximated rounded total length in time
A_reshaped = reshape(A(1:time*Fs), [], time/2); % reshape A (deleting some samples at the end) in time/2 columns
D(1,:) = mean(A_reshaped);
D(2,:) = range(A_reshaped);
[~,idx] = min(D(2,:));
Value = D(1,idx);
Any help is much appreciated.

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by