Is it possible to iteratively increase a number within the middle of a file name?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kellie Wilson
am 9 Aug. 2018
Kommentiert: Kellie Wilson
am 9 Aug. 2018
I have files which are named such that the identifying information is repeated in several places within the filename, and I want to automatically edit the filename each time to code loops through. The specific code I want to change is
Right1 = xlsread('C:\Documents\mouse 5\ 5 Comp1_right_Statistics\ 5 Comp1_right_Cell_Number_Of_Vesicles_VesicleType=Vesicles.csv','A:A');
to
Right1 = xlsread('C:\Documents\mouse 6\ 6 Comp1_right_Statistics\ 6 Comp1_right_Cell_Number_Of_Vesicles_VesicleType=Vesicles.csv','A:A');
automatically such that the next time, all the bolded 5s are 6, then 7, etc. Is there a filler variable or something I can put into the middle of a filename so I can increase the value of that variable and it will automatically insert the new number into it in multiple places (none of which are at the end of the name, unfortunately)?
0 Kommentare
Akzeptierte Antwort
James Tursa
am 9 Aug. 2018
Bearbeitet: James Tursa
am 9 Aug. 2018
E.g., using sprintf
n = some integer
sprintf('Myfilename%dwith%dand%dstuff',n,n,n)
Sample run:
>> n = 5;
>> sprintf('Myfilename%dwith%dand%dstuff',n,n,n)
ans =
Myfilename5with5and5stuff
Put appropriate variation of that into your xlsread. If you will be running into integers more than one digit, you might want to specify a fixed number of digits to use for you string. E.g., instead of %d use %02d or %03d etc. That way the names will arrange nicely in directory lists.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Entering Commands finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!