deleting table above a specific row

4 ビュー (過去 30 日間)
ali hassan
ali hassan 2022 年 2 月 13 日
回答済み: Image Analyst 2022 年 2 月 13 日
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.

回答 (2 件)

KSSV
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
VBBV 2022 年 2 月 13 日
Zero indexing works for Logical arrays in MATLAB, but doesn't work for numeric arrays. Quite Interesting :)

サインインしてコメントする。


Image Analyst
Image Analyst 2022 年 2 月 13 日
Try this:
col12 = (1:5)';
col34 = [1,2,25, 30, 1000]';
t = table(col12, col12, col34, col34)
t = 5×4 table
col12 col12_1 col34 col34_1 _____ _______ _____ _______ 1 1 1 1 2 2 2 2 3 3 25 25 4 4 30 30 5 5 1000 1000
% Find last row where column 3 is exactly 25
row25 = find(t{:, 3} == 25, 1, 'last')
row25 = 3
% Delete rows above that row25
t = t(row25 : end, :)
t = 3×4 table
col12 col12_1 col34 col34_1 _____ _______ _____ _______ 3 3 25 25 4 4 30 30 5 5 1000 1000
% Find first row where column 4 is exactly 30
row30 = find(t{:, 3} == 30, 1, 'first')
row30 = 2
% Delete rows below that row30
t = t(1 : row30, :)
t = 2×4 table
col12 col12_1 col34 col34_1 _____ _______ _____ _______ 3 3 25 25 4 4 30 30

カテゴリ

Help Center および File ExchangeData Types についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by