Function to create duplicate obs based on the value of a string variable
1 次查看(过去 30 天)
显示 更早的评论
In my dataset, I have a variable which takes values like abc-ABC or abc-def-ABC (i.e., one or more lower case codes and one upper case code). I would like to (1) count the number of lower case codes and capture this no. in a new variable (2) multiply the initial observation by this number (e.g., for abc-def-ABC, I would want 2 obs). Can anyone help?
0 个评论
回答(2 个)
Star Strider
2016-8-15
This works:
str = {'abc-ABC'; 'abc-def-ABC'};
r = regexp(str, '[a-z]{3}-');
Result = cellfun(@numel, r, 'UniformOutput',false);
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!