deleting table above a specific row
조회 수: 2 (최근 30일)
이전 댓글 표시
if i have a table and it has 05 columns.
if i want that when column 3 has a value 25, then delete all the rows above it.
and similarly if column 4 has a value 30, then delete the rows in all the columns below this value.
댓글 수: 0
답변 (2개)
KSSV
2022년 2월 13일
% Demo example
x = (1:100)' ;
y = rand(size(x)) ;
T = table(x,y) ;
% remove rows which have values greater than 0.7 values
idx = T.(2)>0.7 ;
% remove the rows
T(idx,:) = [] ;
댓글 수: 1
VBBV
2022년 2월 13일
Zero indexing works for Logical arrays in MATLAB, but doesn't work for numeric arrays. Quite Interesting :)
Image Analyst
2022년 2월 13일
Try this:
col12 = (1:5)';
col34 = [1,2,25, 30, 1000]';
t = table(col12, col12, col34, col34)
% Find last row where column 3 is exactly 25
row25 = find(t{:, 3} == 25, 1, 'last')
% Delete rows above that row25
t = t(row25 : end, :)
% Find first row where column 4 is exactly 30
row30 = find(t{:, 3} == 30, 1, 'first')
% Delete rows below that row30
t = t(1 : row30, :)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Tables에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!