フィルターのクリア

How to filter parts of a structure based on string contents?

8 ビュー (過去 30 日間)
rbme17
rbme17 2018 年 9 月 20 日
編集済み: rbme17 2018 年 9 月 21 日
Hi everyone,
I have used the dir function to recursively store file names from folders and sub folders into a structure, along with their dates and folders/locations.
x = dir(fullfile('location1)','**/*.*'));
y = dir(fullfile('location2','**/*.*'));
I want to extract information from the structure in matlab based on whether the name of a file contains FC#, FC_, and more. Along with the names I want to extract, I would like to keep their corresponding data, such as folder and date.
So, how can I take the information I want and store it in a new structure?
..............................................................................................................
Here is what appears in the command window once I initially store all of the information into the structure for reference
x =
5418×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
Thanks in advance!

採用された回答

Guillaume
Guillaume 2018 年 9 月 20 日
and more
Details of and more would be useful to answer the question properly.
Assuming you want all files that start with FC.
filteredstruct = x(startsWith({x.name}, 'FC'))
If the rule is more complex the filtering function may not be startsWith (maybe regexp) but the principle is the same.
  1 件のコメント
rbme17
rbme17 2018 年 9 月 21 日
編集済み: rbme17 2018 年 9 月 21 日
Hi Guillaume,
Thanks for your answer. I didn't know functions like startsWith existed, but followed that track end used 'contains' instead. It gave me what I was looking for, thanks for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by