Add movefile condition in Matlab

Hi,
I have a question. I've that code and I want to know if it's possible to add a condition to the movefile new name.
clc
clear all
Path = 'C:\EXE1\result\1\'; % path to the files
fileNames= {'0301975168AAA01.tar.gz', '45465456468AAA01.tar.gz'}
for k = 1:length(fileNames)
newFileName = ['fiche' fileNames{k} (3) '_pd_' fileNames{k}(3:5) '.tar.gz'];
% renaming
movefile([Path fileNames{k}], [Path newFileName]);
end
So, my condition would be something like this, for example:
This is one of my files
'0301975168AAA01.tar.gz'
And this is the the result after running the code:
fiche0_pd_01.tar.gz
And the condition will be:
fileNames{k} (3)>0-5 = 2
fileNames{k} (3)>5-10 = 2
So, in that case=
fileNames{k} (3)= 0 So it would be 2, not 0
fiche2_pd_01.tar.gz
Does somebody know how can I do it?
Thanks in advance and greetings,

댓글 수: 4

Walter Roberson
Walter Roberson 2012년 10월 16일
You indicate 10 as your upper bound in the second condition, but you seem to be working with only a single digit?
0-5 and 5-10 together seem to cover everything for a single digit, so it is not clear what the conditional would achieve?
Emmanuelle
Emmanuelle 2012년 10월 16일
Hi Walter. First of all, thank you for your quickly reply. Sorry, this is because I've a lot of files and I would have to apply for more than one number, not only one digit, as in the example. So, for example, the condition would be like this:
fileNames{k} (3)>0-5 = 2 fileNames{k} (3)>5-9 = 2
I've got a lot of files, so this is the reason I want to introduce a condition.
Walter Roberson
Walter Roberson 2012년 10월 16일
Still looks to me as if you are always changing the digit to 2 ?
Ah! Sorry it was my fault! For example,
fileNames{k} (3)>0-5 = 2
fileNames{k} (3)>5-9 = 8

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2012년 10월 16일

0 개 추천

Use lookup tables.
For example, supposing 5 was to be left alone and 7 was to become 5 and the other digits were to become 2:
lookup3 = '2222252522';
newdigit = lookup3(fileNames{k}(3)-'0'+1);

댓글 수: 1

Emmanuelle
Emmanuelle 2012년 10월 16일
편집: Emmanuelle 2012년 10월 16일
Ah! I think I know what you mean but it's not like this. This is my real example:
XXX
if fileNames{k}(4:9)<10000= 31
fileNames{k}(4:9)>20000= 28
fileNames{k}(4:9)>10001>19999 =30
this is the exactly condition. And then I want to add it on the rename name.
newFileName = ['fiche' fileNames{k} (3) '_pd_' fileNames{k}(3:5) *'XXX'* '.tar.gz'];
I don't know if this is possible with Matlab. I'm going to check what lookup works.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

질문:

2012년 10월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by