How to read xlsx file after the date

5 ビュー (過去 30 日間)
Jingying Wang
Jingying Wang 2017 年 12 月 22 日
回答済み: Ramnarayan Krishnamurthy 2017 年 12 月 29 日
Hi everyone. I want to read the file by date. That means, the first produced file should be read first and then second and so on. The name of xlsx file looks like: (CS2_33_D_M_Y) CS2_33_8_17_10 CS2_33_8_18_10 CS2_33_8_19_10

回答 (1 件)

Ramnarayan Krishnamurthy
Ramnarayan Krishnamurthy 2017 年 12 月 29 日
A possible approach would be to pull out the date from the file name and then sort it. Then, keep a track of the order and read the files in that order.
As an example:
% Sample file names in a cell array
A = {'CS2_33_10_17_10'; 'CS2_33_10_10_10'; 'CS2_33_8_1_12'; 'CS2_33_8_18_11' ; 'CS2_33_1_1_01'};
% Reading the date part of the file assuming the prefix CS2_33_ is a constant amongst filenames
for i=1:length(A)
a{i}=sscanf(A{i}, 'CS2_33_%s');
end
% Sorting the dates and tracking the changes to the indices
[~,j] = sortrows(datenum(a))
% A{j} contains filenames in the ascending order of dates
xlsread(A{j})
If you are interested in using the "intrinsic" timestamp of the files, the following link may be useful: https://www.mathworks.com/matlabcentral/answers/33220-how-do-i-get-the-file-date-and-time

カテゴリ

Help Center および File ExchangeWorkspace Variables and MAT-Files についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by