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!