how to use strfind (or other method) to look in cell array to find strings NOT containing a certain pattern
Ältere Kommentare anzeigen
Hello! I am trying to develop an automated plotting code for experimental results which scans through given folders and imports and plots the data in the files based on the name of the file. At the moment I import an array of cells for the filenames (each cell containing a single filename as characters) and a matrix with the associated data in it as doubles (number of columns = number of filename cells). I cycle through the filenames and only import/plot the data if the file name includes key strings like "IdsVbg", "PBS", "exo"...
For example:
if strfind(y{n}, 'PBS') & strfind(y{n}, 'flush')
p=plot(IdsVtgdata(2:end,n,2)/0.001,IdsVtgdata(2:end,n,1)/0.001,'color',cmapPBS(n,:));
end
Where y is the cell array of filenames and IdsVtgdata is the matrix of my data. This works fine, except instead of the above, I would like to plot something based on a filename that contains "PBS" but specifically NOT "flush". I tried
if strfind(y{n}, 'PBS') & not(strfind(y{n}, 'flush'))
and
if strfind(y{n}, 'PBS') & (strfind(y{n}, ~'flush'))
but I get errors every time, either "PATTERN must be a single string" (for the former) or "Undefined operator '~' for input arguments of type 'cell'" (for the latter).
Is there a way of using strfind, or any other function for that matter, to find a file who's name contains "PBS" but doesn't contain "flush"? Apologies, I feel like this should be super simple but I can't seem to find anything online. Of course I could re-consider my filenaming convention, but for the purposes of passing over data to the next person, it is useful to have ludicrously descriptive filenames.
Many thanks!
P.S. I have put matlab 2016a as the release but I also have 2018a.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!