Directory not loading in the correct order

7 ビュー (過去 30 日間)
Joe
Joe 2013 年 7 月 1 日
I am trying to load multiple data sets (30 files) into a structured array but my data is not matching with my folder order. I create my working directory and then access it
wd='C:\Data\Joe\28-Jun-2013\pair 14c\';
CClist=dir([wd '*AltS*.mat']);
%Coupling data (individual)
temp2=[]; bigarray2=[];
for i2=1:length(CClist)
d2=load([wd CClist(i2).name]);
data2=d2.data;
temp2=onerunoneAltS(data2, SliceTime, Age, wd);
bigarray2=[bigarray2; temp2];
end
This successfully loads all of the files into bigarray2 but it does so out of order. my CClist order does not match the files in my directory....
For example, CClist(1) gives me the time stamp 1500, CClist(2) time stamp 1543, CClist(3) time stamp 1501.....I want them to be concatenonized in the order that it is in my folder 'pair 4c' which the time stamp is correct. All of these files are in the correct order with the correct labels and time stamps. I did rename some of the files ...does this have an effect? my 'Date modified" section of the folder gives me the time stamps and they are all correct. Any help would be appreciated thanks!

採用された回答

Jonathan Sullivan
Jonathan Sullivan 2013 年 7 月 1 日
Just sort the list of file by date before doing anything with them.
Example
% Get the files in the directory
wd='C:\Data\Joe\28-Jun-2013\pair 14c\';
CClist=dir([wd '*AltS*.mat']);
% Sort them by date
[~,ind] = sort([CClist.datenum]);
CClist = CClist(ind);
  1 件のコメント
Joe
Joe 2013 年 7 月 1 日
Thanks it works perfectly!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeFile Operations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by