Finding a string exact match
显示 更早的评论
I have a list of parameters
parameters = {'Freq','I','U','P','Q','S','PF'};
and a list of names
names = {'Freq_min', 'Freq_max, 'Freq_avg','I_min', 'I_max,I_avg'....} and so on. Every parameter has many values like min, max, avg, peak, etc. There are 140 names in the array.
names is a cell array that contains the variable names from table T.
I need to find every position in the array names that has the string 'Freq' and then pull all data rows in that column, so this is the code i'm using:
for n = 1:length(parameters)
x = parameters(~ismember(parameters,parameters{n}));
s.(strcat(parametros{n},'_','Min')) = ...
T(:,contains(names,parameters{n})&contains(nombres,'Min')&strncmpi(parameters(n),names,2));
s.(strcat(parametros{n},'_','Avg')) = ...
T(:,contains(nombres,parameters{n})&contains(names,'Avg')&strncmpi(parameters(n),names,2));
s.(strcat(parametros{n},'_','Max')) = ...
T(:,contains(nombres,parameters{n})&contains(names,'Max')&strncmpi(parameters(n),names,2));
end
And it works well, until it hits 'PF' because it also finds 'P' and i cannot find the way for Matlab to discriminate for 'P' not being containd in 'PF'
Or maybe I'm just over complicating the solution and there's an easier way.
Thanks.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Data Type Conversion 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!