Clear Filters
Clear Filters

Delete table row if var1 not equal to certain string

6 views (last 30 days)
Dear All,
as mentioned above I am trying to delete a rows of a table if the variable (column) "NATION" is not equal to "UNITED STATES". A similar problem is discussed here, unfortuantely the code presented does not help me a lot. I tried to use:
definitions(cellfun(@isempty, strfind(definitions.NATION, 'UNITED STATES')),:)
which deletes all UNITED STATES entries, but thats the opposite of what I want. I need the same thing with NOT united States as critereon. It seems like there should be a solution to this. Can anyone help??
I would really appreciate it!!

Accepted Answer

Azzi Abdelmalek
Azzi Abdelmalek on 24 May 2016
%-------------------Example------------------------
s={ 'Algeria',1 2;'United States' 3 4;'France' 6 7}
A=cell2table(s)
%------------------------------------------------------
idx=ismember(A.s1,'United States')
A(~idx,:)=[]
  2 Comments
roblocks
roblocks on 24 May 2016
Dear Azzi Abdelmalek,
thanks for your help, problem solved. Are you aware of a good compendium which discusses how to solve problems like the one above? I only know of this, and it is way to short. Basically like a list of useful commands if one wants to organize, format and display desciprtive statstics of data in tables (and structures for taht matter).
Any idea? :)
Best, and thanks again!
Stephen23
Stephen23 on 24 May 2016
Edited: Stephen23 on 24 May 2016
@roblocks: the documentation "Contents" on the left-hand side of the page are a clickable hierarchy of pages: if you open the page that you found then you can click on "Tables" to go up one level: there you will find all topics discussing tables and how to use them. You will also see that there is a similar section explaining structures...
Two minutes spent learning how to use the Contents will be time well spent: you will learn how to find information all by yourself without having to ask random stranger on the internet, and you might just discover some thing new too!

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!