Accepting and rejecting values in numeric array

2 visualizzazioni (ultimi 30 giorni)
sam van Bohemen
sam van Bohemen il 28 Ott 2020
Commentato: KSSV il 28 Ott 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.
226 214
543 530
858 846
1175 1162
1482 1469
1782 1770
2953 2965
2976 3836
3848 4419
4431 NaN
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.
226 213
571 559
917 903
1261 1249
1605 1593
1939 1927
2270 2258
2576 2589
2602 2921
2908 3255
2932 3595
3267 3935
3607 NaN
3948 NaN
Is sombody able to help me create a script that will allow me to do this?
Thanks,
Sam

Risposte (1)

KSSV
KSSV il 28 Ott 2020
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
A = 10×2
3 7 6 4 7 3 8 4 1 5 7 4 8 7 NaN 7 NaN 9 NaN 6
  2 Commenti
sam van Bohemen
sam van Bohemen il 28 Ott 2020
Hi KSSV,
Thanks for your reply.
However, I am not looking to remove values from column 1 that are greater than a particular number but rather I would like to remove values in column 1 that are not <= 15 samples greater than any value in column 2.
KSSV
KSSV il 28 Ott 2020
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.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by