フィルターのクリア

Help with if-else statement?

2 ビュー (過去 30 日間)
Lianna Johnson
Lianna Johnson 2013 年 6 月 5 日
Hi. So I have these files...
'20130401_SPLBRENT3_concat.mat'
'20130402_SPLBRENT3_concat.mat'
'20130403_SPLBRENT3_concat.mat'
'20130404_SPLBRENT3_concat.mat'
'20130405_SPLBRENT3_concat.mat'
'20130410_SPLBRENT3_concat.mat'
'20130411_SPLBRENT3_concat.mat'
'20130422_SPLBRENT3_concat.mat'
'20130424_SPLBRENT3_concat.mat'
'20130425_SPLBRENT3_concat.mat'
'20130426_SPLBRENT3_concat.mat'
'20130427_SPLBRENT3_concat.mat'
'20130429_SPLBRENT3_concat.mat'
'20130430_SPLBRENT3_concat.mat'
'20130501_SPLBRENT3_concat.mat'
'20130502_SPLBRENT3_concat.mat'
'20130503_SPLBRENT3_concat.mat'
'20130506_SPLBRENT3_concat.mat'
'20130517_SPLBRENT3_concat.mat'
'20130518_SPLBRENT3_concat.mat'
'20130519_SPLBRENT3_concat.mat'
'20130520_SPLBRENT3_concat.mat'
'20130521_SPLBRENT3_concat.mat'
'20130522_SPLBRENT3_concat.mat'
'20130523_SPLBRENT3_concat.mat'
'20130524_SPLBRENT3_concat.mat'
'20130527_SPLBRENT3_concat.mat'
'20130528_SPLBRENT3_concat.mat'
'20130529_SPLBRENT3_concat.mat'
'20130530_SPLBRENT3_concat.mat'
'20130531_SPLBRENT3_concat.mat'
These are data files from April (201304) and May (201305). I am trying to do an "if else" statement that will send the files with the first numbers 201304 to the path 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1304' and the files with the numbers 201305 to the path 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1305'. Notice that files aren't there from every day, so they're not a sequence. I'm pretty sure this is done with "if else" but I am not sure.
Can anyone help?
Thanks

採用された回答

Jan
Jan 2013 年 6 月 5 日
編集済み: Jan 2013 年 6 月 5 日
Let the OS perform the pattern matching:
Dest1 = 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1304';
Dest2 = 'T:\10 - VEHICLE TESTING RESULTS\2011 KENWORTH ISX15\10 - CANAPE FILES\1305';
Source = 'D:\ParentFolderOfYourFiles';
movefile(fullfile(Source, '201304*.mat'), Folder1);
movefile(fullfile(Source, '201305*.mat'), Folder2);

その他の回答 (1 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 5 日
編集済み: Azzi Abdelmalek 2013 年 6 月 5 日
fic=dir('current_path/*.mat')
f={fic.name}
idx=cellfun(@(x) ~isempty(regexp(x,'201305')),f)
for k=1:numel(idx)
a1=fullfile('current_path/' f{idx});
a2=fullfile('path1/' f{idx});
movefile(a1,a2)
end
idx1=cellfun(@(x) ~isempty(regexp(x,'201304')),f)
for k=1:numel(idx1)
a1=fullfile('current_path/' f{idx1});
a2=fullfile('path2/' f{idx1});
movefile(a1,a2)
end
  1 件のコメント
Jan
Jan 2013 年 6 月 5 日
編集済み: Jan 2013 年 6 月 5 日
I suggest to replace:
idx = cellfun(@(x) ~isempty(regexp(x,'201305')),f)
by
idx = strncmp(f, '201305', 6);

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

カテゴリ

Help Center および File ExchangeTest Cases and Iterations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by