How to extract entire rows based on values placed in a single column in a matrix?
28 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi everyone,
I have a 100x10 table, let's call it CH_channel. i have got 3 questions. If you are able to find a solution for every task, you will be a hero to me, otherwise, if you manage to solve only the first task, it would be really appreciated as well.
- in this matrix, i want to find all the values exceeding a value x (let's say 7) only in column number 5. Then I would like to retain all the values in the same row;
- once done this, I would like to "crop" 1 row before the x value and 2 rows after it within the CH_channel.
- I would like to create a new table in 3 dimension, where every "cropped" epoch represent a dimension (they are supposed to be trials).
note that if you end up with 2 consecutive rows where you have 2 or more values >7, you will need to start computing the rows to retain only from the first values exceding the x.
right now, I am stucked, please help.
the final results, according to the following table should be:
- for the first point, the code should retain all the values in rows 8 and 12 (for all columns);
- crop/cut all the values within rows 7:10 and from rows 11:14
- with the values "extracted" outr of the matrix CH_channel, i would like to create a brand new 3D matrix, where these "cropped" rows represent different epochs (or trials)
CH_channel = array2table(randi(8,16, 5))
5 commentaires
Voss
le 26 Oct 2022
- in this matrix, i want to find all the values exceeding a value x (let's say 4) only in column number 33. Then I would like to retain all the values in the same row;
% make the table:
CH_channel = array2table(randi(10,100, 33))
% rows where column 33 > 4:
idx = CH_channel{:,33} > 4
% keep those rows:
values_to_keep = CH_channel(idx,:)
Réponses (1)
David Hill
le 26 Oct 2022
H = array2table(randi(10,100, 33));
f=find(H{:,33}>4);
f=f(diff(f)>1);%removes consecutive rows >4
for k=1:length(f)
c{k}=H(max(1,f(k)-5):min(100,f(k)+10),:);
end
c
0 commentaires
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!