Read file whose name has a pattern that is part of another file name pattern

8 views (last 30 days)
I have files with two patterns in their names: "" and "".
Currently I'm using:
filePattern = fullfile(Exp_Path,strcat('*',Sampling_Rate,'.nc'));
ncFiles = dir(filePattern);
with Sampling_Rate being a string (either 'daily' or '4xdaily'), and with Exp_Path being the directory containing the relevant files.
For the "4xdaily" pattern, this works properly, giving me a structure with all the requested files and only them.
When I try to apply this to the the "daily" pattern, I get a structure with both kinds of files (which makes sence, as the string 'daily' is included in the larger string '4xdaily').
Is there a way to obtain only the "daily" files?

Accepted Answer

Ive J
Ive J on 14 Jan 2022
Edited: Ive J on 14 Jan 2022
Try this
files = {dir("*").name}.'
{'' }
{'' }
xdailyIdx = endsWith(files, '');
xdailyf = files(xdailyIdx)
dailyf = files(~xdailyIdx)
{'' }

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by