Finding a string exact match
Mostrar comentarios más antiguos
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.
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!