How to extract entire rows based on values placed in a single column in a matrix?
28 次查看(过去 30 天)
显示 更早的评论
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 个评论
Voss
2022-10-26
- 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,:)
回答(1 个)
David Hill
2022-10-26
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!