MATLAB Answers

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

1 view (last 30 days)
Antonio Morales
Antonio Morales on 4 Mar 2017
Edited: Antonio Morales on 4 Mar 2017
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.

Answers (0)

Community Treasure Hunt

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

Start Hunting!