MATLAB Answers

Find column names with particular names in MATLAB table

163 views (last 30 days)
Hi there,
I have a massive table with 408 columns in MATLAB. I want to get rid of columns that start with the word "connected". Instead of having to manually check the table and do something like
finalnbs(:,212:364) = [];
Where
finalnbs
is the table, how do I find all columns in finalnbs which start with connected e.g.
connected*
And then remove those?

  1 Comment

harjeet singh
harjeet singh on 21 Dec 2015
please upload mat table, and let me know the datatype of finalnbs

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 21 Dec 2015
finalnbs(:,strncmp(finalnbs.Properties.VariableNames, 'connected', length('connected')) ) = [];

  0 Comments

Sign in to comment.

More Answers (2)

Renato Agurto
Renato Agurto on 21 Dec 2015
Edited: Renato Agurto on 21 Dec 2015
Hello
if "titles" is the first row of your table, then:
titles = finalnbs(1,:);
%Select the columns that should stay
idxs = cellfun(@(x) length(x) < 9 || ~strcmp(x(1:9),'connected'),titles);
finalnbs = finalnbs(:,idxs);

  0 Comments

Sign in to comment.


Joseba Moreno
Joseba Moreno on 14 Feb 2019
Hello,
I have a similar problem but in my case I would like to remove the columns which contain the word "free".
How can I do that?
Thanks!
Joseba

  2 Comments

Walter Roberson
Walter Roberson on 14 Feb 2019
With new enough matlab you can use contains() to test whether a substring occurs somewhere in a string .

Sign in to comment.

Sign in to answer this question.