How can I change the label for my elements with same name?
2 次查看(过去 30 天)
显示 更早的评论
How can I count the the strings with the sabe value and then add them in another ID with the increasing number for the elements with the same label
For example I have the next vector
A = {'1_01';'1_01';'1_01';'1_02';'1_02'}
and the result should be this
B = {'1_01-1';'1_01-2';'1_01-3';'1_02-1';'1_02-2'}
str1 = '-';
0 个评论
采纳的回答
Chunru
2021-8-12
A = {'1_01';'1_01';'1_01';'1_02';'1_02'};
uA = unique(A);
B = A;
for i=1:length(uA)
idx = find(strcmp(A, uA(i)));
for j=1:length(idx)
B{idx(j)} = sprintf('%s-%d', B{idx(j)}, j);
end
end
%B = {'1_01-1';'1_01-2';'1_01-3';'1_02-1';'1_02-2'}
B
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!