Exclude a keyword from a file search?

3 vues (au cours des 30 derniers jours)
Jacqueline
Jacqueline le 24 Juil 2013
Hi, so I have a set of files such as:
'20130723_SPLBRENT3_000003.mat'
'20130723_SPLBRENT3_005948.mat'
'20130723_SPLBRENT3_015948.mat'
'20130723_SPLBRENT3_025948.mat'
'20130723_SPLBRENT3_035949.mat'
'20130723_SPLBRENT3_045948.mat'
'20130723_SPLBRENT3_055948.mat'
'20130723_SPLBRENT3_065948.mat'
'20130723_SPLBRENT3_075949.mat'
'20130723_SPLBRENT3_085949.mat'
'20130723_SPLBRENT3_095949.mat'
'20130723_SPLBRENT3_102025.mat'
'20130723_SPLBRENT3_102931.mat'
'20130723_SPLBRENT3_112947.mat'
'20130723_SPLBRENT3_122947.mat'
'20130723_SPLBRENT3_132947.mat'
'20130723_SPLBRENT3_142947.mat'
'20130723_SPLBRENT3_152947.mat'
'20130723_SPLBRENT3_162947.mat'
'20130723_SPLBRENT3_172947.mat'
'20130723_SPLBRENT3_180744.mat'
'20130723_SPLBRENT3_190749.mat'
'20130723_SPLBRENT3_200749.mat'
'20130723_SPLBRENT3_concat.mat'
These are files from yesterday (7/23), and I made a concat file that combines all the files into one, which is at the bottom. I'm writing a code that counts the number of files that were uploaded yesterday, but I don't want the concat file to count. Is there anyway I can exclude the concat.mat file?

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 24 Juil 2013
file={'20130723_SPLBRENT3_180744.mat'
'20130723_SPLBRENT3_190749.mat'
'20130723_SPLBRENT3_200749.mat'
'20130723_SPLBRENT3_concat.mat'}
new_file=file( cellfun(@(x) isempty(regexp(x,'concat')),file))
  2 commentaires
Jacqueline
Jacqueline le 24 Juil 2013
Thank you!
Jan
Jan le 26 Juil 2013
Modifié(e) : Jan le 26 Juil 2013
Again I mention, that cellfun is slow when combined with anonymous functions. I do not see a reason to let Matlab waste time and suggest:
new_file = file(cellfun('isempty', regexp(file, 'concat')))
And if you do not like the string methods of cellfun, this is at least faster than the anonymous function:
new_file = file(cellfun(@isempty, regexp(file, 'concat')))
@Azzi: Do you think it is worth to suggest the faster cellfun methods without anonymous functions in the forum? Is there any reason that you avoid them?

Connectez-vous pour commenter.

Plus de réponses (1)

Jan
Jan le 26 Juil 2013
If this is time-critical, you can use FEX: strncmpr, which is identical to strncmp but compares the end of the string:
new_file = file(~strncmpr(file, '_concat.mat', 11));

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by