Find column names with particular names in MATLAB table
18 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2015-12-21
finalnbs(:,strncmp(finalnbs.Properties.VariableNames, 'connected', length('connected')) ) = [];
0 个评论
更多回答(2 个)
Renato Agurto
2015-12-21
编辑:Renato Agurto
2015-12-21
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 个评论
Joseba Moreno
2019-2-14
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 个评论
Walter Roberson
2019-2-14
With new enough matlab you can use contains() to test whether a substring occurs somewhere in a string .
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!