Hi experts,
I want to rename a bunch of variables (ppn) by extending them with '_01' and I want to extend duplicate variablenames with '_02'. The problem is that I get variables named 'BG1028_02_01'. I hope someone can help me!
ppn = {'BG1026';'BG1027';'BG1028';'BG1028';'BG1029';'BG1030'} for i = 1:length(ppn)-1 j = i + 1; d = strcmp(ppn{i},ppn{j}); if d == 0; ppn{i} = strcat(ppn{i},['_01']); else d = 1; ppn{i} = strcat(ppn{i},['_01']); ppn{j} = strcat(ppn{j},['_02']); continue; endend
This is what I get:
ppn = 'BG1026_01' 'BG1027_01' 'BG1028_01' 'BG1028_02_01' 'BG1029_01' 'BG1030'
Best Answer