필터 지우기
필터 지우기

Remove row if its value is not different enough from the value in the row above it.

조회 수: 1 (최근 30일)
I have the table above. If the difference between latencies in one row is not much different from the latencies in the second row (difference <= 100), I would like to have the second row removed. To illustrate, row 305 would be removed in the table above because the difference in latencies between it and row 304 is less than 100. Would really appreciate suggestions on how best to do this, thank you!

채택된 답변

Chunru
Chunru 2022년 8월 16일
% Generate data
latency = [1000 1010 1020 1800]';
dur = zeros(size(latency));
type = ones(size(latency)) * 256;
T = table(latency, dur, type)
T = 4×3 table
latency dur type _______ ___ ____ 1000 0 256 1010 0 256 1020 0 256 1800 0 256
% diff
ldiff = diff(T.latency);
idx = find(ldiff <= 100) + 1;
T(idx, :) =[];
T
T = 2×3 table
latency dur type _______ ___ ____ 1000 0 256 1800 0 256

추가 답변 (1개)

Simon Chan
Simon Chan 2022년 8월 16일
Let A be your matrix, try the following:
threshold = 100;
A([false;(diff(A(:,1))<=threshold)],:)=[];
  댓글 수: 1
Aleya Marzuki
Aleya Marzuki 2022년 8월 16일
Yup this worked too! Just needed to make a minor adjustment since A is a table:
A([false;(diff(A.latency)<=threshold)],:)=[];
Thank you!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by