load several .mat Files in For-Loop for several dates with one condition.

1 view (last 30 days)
i have one mat file which contains 80 rows in 'yyyymmdd' format. i have another folder with 238 mat files with same 'yyyymmdd' as mat file names. i want to load contents from the folder mat file to the first mat file where the date from the folder is less than the date of the first mat file.
eg.
mat file which has 80 rows
19900102
19900301
19900603
19900903
19901202
19900303
........ up to
20080901.
next i have folder of 238 .mat files with following names
19891231.mat
19900131.mat
19900228.mat
19900328.mat
19900430.mat
.....up to
20080930.mat
so i want output as 2 columns
column1(which has 80 rows) column2(contents from the below mentioned mat file)
19900102 19891231.mat
19900301 19900131.mat
19900228.mat
19900328.mat
the condition is if we look at second row date is 19900301 i need contents of 19900228.mat file not 19900131 or 19900328 likewise i need for all 80 rows.
Thanks in Advance!!!
  2 Comments
Walter Roberson
Walter Roberson on 28 Oct 2021
I do not understand what is being asked for.
  • I do not understand how the file is chosen for the second column. Is it the most recent file before the target point? If so then does that imply that the same content could be repeated, if there was a gap in files so that the same file was the most recent compared to several of the dates?
  • You say that you want the contents from the mentioned .mat file, but you want to put them into a column. Your first column is numeric; to get the contents of the .mat file then each element of the second column would have to be a struct with one field for each variable in the file. Is the overall output to be a cell array? Is it to be a table() ?
Suresh R
Suresh R on 29 Oct 2021
this is the output required in excel - i have attached photo with output required in excel.
as you can see in this photo the column values in A is the first mat file which contains 80 dates.
in b column it is the matfile name which contains values which are in columns C,D,E. this Mat file has size of 1500 X 3 values.
Likewise we have 238 matfiles for B column. we not need to print every matfile in B column.
we need to find the immediate date before the date present in Column A. that is if you see column A has date as 20020102 we need to find date which date is immediate before this date and print those contents in excel. in this case for 20020201 the immediate date before is 20011231.mat this file. so we have to print the contents in this mat file to this date 20020201. Hope you understand.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!