How to delete specific rows in a table based on a value?

조회 수: 42 (최근 30일)
Carl Schneegaß
Carl Schneegaß 2020년 12월 13일
답변: Carl Schneegaß 2020년 12월 16일
Hi all,
I have a big table with 6 columns and would like to delete all rows where one column contains a specific value.
That's how the table looks like:
I would like to delete all rows, where T.ISIN == 'DE0006205701'
May you please help me with this?
Thanks so much in advance!
  댓글 수: 5
Carl Schneegaß
Carl Schneegaß 2020년 12월 13일
I had thought about something like
T = T(T.ISIN~='DE0006205701',:);
but it doesn't work for cell..
Carl Schneegaß
Carl Schneegaß 2020년 12월 13일
I think the solution is
T = T(~contains(T.ISIN,'DE0006205701'),:);

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

채택된 답변

Carl Schneegaß
Carl Schneegaß 2020년 12월 16일
I fortunately found the answer myself, it's
T = T(~contains(T.ISIN,'DE0006205701'),:);
Moroever, check out Image Analyst's solution, it works too!

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 12월 13일
Did you try ismember like I suggested above?
s = load('answers.mat')
T = s.T;
whos T % Show size.
% I would like to delete all rows, where T.ISIN == 'DE0006205701'
pattern = 'DE0006205701'
[ia, ib] = ismember(T.ISIN, {pattern});
fprintf('Found %d rows where ISIN = "%s". We will delete those.\n', sum(ia), pattern);
T(ia, :) = [];
whos T % Show size now.
  댓글 수: 1
Carl Schneegaß
Carl Schneegaß 2020년 12월 13일
thanks a lot for your help, this definitely works!
I think maybe even easier might be
T = T(~contains(T.ISIN,'DE0006205701'),:);

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

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by