Matching multiple file names

6 ビュー (過去 30 日間)
Pouya Pourkarim
Pouya Pourkarim 2022 年 4 月 19 日
編集済み: Pouya Pourkarim 2022 年 4 月 19 日
I have two types of data each in a seperate folder. Lets say I have magnetic field files in folder x and electric field files in folder y.
There are 365 magnetic field files each represnting one day of measurments. However electric field files are more than 365 and there are multiple files per day. For example, we have electric field files measured from 00:00:00 to 10:30:00 in one file for a day and then 11:00:00 to 23:59:59 in another file for the same day. Note that for some days there are more than two electric field files.
I want MATLAB to open magetic field file
"SW_OPER_MAGA_HR_1B_20140101T000000_20140101T235959_0505_MDR_MAG_HR_processed.mat" from it's folder
then open electric field files
which belong to the same day as magnetic field file as shown by data timestamp in file names. I was not succeful in using regexp and dir functions.
Thanks in advance,


Chris 2022 年 4 月 19 日
編集済み: Chris 2022 年 4 月 19 日
You'll have to fill in some of the blanks because I don't know how you're opening files, but to find the corresponding filenames in the electric field folder...
magstr = "SW_OPER_MAGA_HR_1B_20140101T000000_20140101T235959_0505_MDR_MAG_HR_processed.mat";
pat = "_" + digitsPattern(8) + "T";
thedates = extract(magstr,pat);
% eFieldNames = {dir().name};
eFieldNames = {'SW_EXPT_EFIA_TCT16_20140101T000000_20140101T103000_0302_processed.mat',
filesToOpen = contains(eFieldFnames,thedates(1))
filesToOpen = 3×1 logical array
1 0 1
  14 件のコメント
Pouya Pourkarim
Pouya Pourkarim 2022 年 4 月 19 日
Thanks, it actually solved the problem with the Brace indexing error that I was getting.


その他の回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by