필터 지우기
필터 지우기

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 CenterFile Exchange에서 Test Cases and Iterations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by