Function to create duplicate obs based on the value of a string variable
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (2)
Star Strider
il 15 Ago 2016
This works:
str = {'abc-ABC'; 'abc-def-ABC'};
r = regexp(str, '[a-z]{3}-');
Result = cellfun(@numel, r, 'UniformOutput',false);
0 Commenti
Azzi Abdelmalek
il 15 Ago 2016
str='abc-def-keh-ABC'
a=regexp(str,'[a-z]+','match')
out1=numel(a)
0 Commenti
Vedere anche
Categorie
Scopri di più su Characters and Strings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!