source: trunk/src/rename_indexing.m @ 1102

Last change on this file since 1102 was 1078, checked in by sommeria, 5 years ago

various updates

File size: 719 bytes
Line 
1% add an index to a name, or increment an existing index, if the proposed Name (char string) already exists in the list ListName (cell)
2function NewName = rename_indexing(Name,ListName)
3
4detectname=1;
5NewName=Name;
6while ~isempty(detectname)
7    detectname=find(strcmp(NewName,ListName),1);%test the existence of the proposed name in the list
8    if detectname% if the name already exist
9        rr=regexp(NewName,'(\d+)$'); %look for numerical indexing at the end of NewName
10        if isempty(rr)
11            NewName=[NewName '_1'];%add the index 1
12        else
13            newindex=str2num(NewName(rr:end))+1; %increment the index by 1
14            NewName=[NewName(1:rr-1) num2str(newindex)];
15        end
16    end
17end
Note: See TracBrowser for help on using the repository browser.