How to extract a number from a string array?
Mostra commenti meno recenti
4 Commenti
Dayne Coleman
il 21 Giu 2018
Modificato: Dayne Coleman
il 21 Giu 2018
Juan Fernandez
il 21 Giu 2018
Modificato: Juan Fernandez
il 21 Giu 2018
Have you looked through the documentation page for the sscanf(_) function? That might provide you a solution.
Dayne Coleman
il 21 Giu 2018
Dayne Coleman
il 21 Giu 2018
Risposta accettata
Più risposte (1)
Juan Fernandez
il 21 Giu 2018
I searched through older questions and found a similar one from 2012. The solution requires the use of regexp(_). Here's my implementation.
str1 = '(164) - (165)';
str2 = '(165) - (166)';
str3 = '(165) - (166)';
strs = {str1,str2,str3};
output = zeros(length(strs),1);
for iter=1:length(strs)
num_strs = regexp(strs{iter},'\d*','Match');
output(iter) = str2double(num_strs{1});
end
Categorie
Scopri di più su Characters and Strings in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!