Find column names with particular names in MATLAB table

34 vues (au cours des 30 derniers jours)
Dhruv Ghulati
Dhruv Ghulati le 21 Déc 2015
Commenté : Peter Perkins le 17 Fév 2019
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 commentaire
harjeet singh
harjeet singh le 21 Déc 2015
please upload mat table, and let me know the datatype of finalnbs

Connectez-vous pour commenter.

Réponse acceptée

Walter Roberson
Walter Roberson le 21 Déc 2015
finalnbs(:,strncmp(finalnbs.Properties.VariableNames, 'connected', length('connected')) ) = [];

Plus de réponses (2)

Renato Agurto
Renato Agurto le 21 Déc 2015
Modifié(e) : Renato Agurto le 21 Déc 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);

Joseba Moreno
Joseba Moreno le 14 Fév 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 commentaires
Walter Roberson
Walter Roberson le 14 Fév 2019
With new enough matlab you can use contains() to test whether a substring occurs somewhere in a string .
Peter Perkins
Peter Perkins le 17 Fév 2019
or strfind in older versions.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Electrical Block Libraries dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by