Accepting and rejecting values in numeric array
3 views (last 30 days)
Show older comments
sam van Bohemen on 28 Oct 2020
Commented: KSSV on 28 Oct 2020
I am analysing ECG data. I have a numeric array containing two colums.
The first column contains the location of detected ECG peaks while the second column contains the location of detected ECG troughs.
I want to align the values in each row so every ECG peak location is adjacent to the corresponding ECG trough location. Every ECG peak location is always <15 samples greater than the corresponding ECG trough location.
ie: For every row, I want to accept the values where the value in column 1 is <15 samples greater than the value in column 2.
When this condition is not met I want to delete the value that prevents this condition from being met.
In the example below I would like to delete 2953. I would then like to shift the values in column 1 up one row to replace the deleted value and add a NaN at the bottom of column 1 to complete the array. I would like to finish the code by deleting all NaNs.
In another example, I would like to delete 2576 and 2908 and shift the values in column 1 up two rows to replace the deleted values and add a 2 x NaN at the bottom of column 1 to complete the array.
Is sombody able to help me create a script that will allow me to do this?
A = randi(10,10,2) ; % random data for demo
% Remove values greater than 8 in column 1
idx = A(:,1)>8 ; % get indices of values > 8
A(:,1) = [ A(~idx,1) ; NaN(nnz(idx),1)] % shift and append NaN's in the first column
Okay..that is not a problem..use the given example and extend it to your case. You need to change the condition of removing elemnts thats it.
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!