How to find columns by name in a cell aray
11 次查看(过去 30 天)
显示 更早的评论
Hello all,
Let's say I have a large cell array with similar variable names in the first row (A_F1 , B_F2 , A_F2 , G_F5 ...) followed by data.
I want to create a smaller cell array with just the columns where the variable name starts with A.
How would I do that?
Thank you
0 个评论
采纳的回答
Stephen23
2017-4-11
编辑:Stephen23
2017-4-11
This is easy with strncmp:
>> inp = {'A_F1','B_F2','A_F2','G_F5';1,2,3,4}; % demo matrix.
>> idx = strncmp(inp(1,:),'A',1); % indices of strings starting with A.
>> otp = inp(:,idx); % select those columns from inp.
As an alternative you could use the table class, and this task may well be easier.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!