Effacer les filtres
Effacer les filtres

How to extract number from this string cell?

89 vues (au cours des 30 derniers jours)
Mahdi Khademishamami
Mahdi Khademishamami le 16 Oct 2022
Commenté : Star Strider le 16 Oct 2022
Hi everyone,
I have a string array like below:
") injection-dr0015:138751)"
") injection-dr0015:68761)"
") injection-dr0015:122762)"
") injection-dr0015:83759)"
") injection-dr0015:163753)"
I would like to extract the numbers after : , like:
138751
68761
122762
83759
163753
I appreciate for any ideas or solution.
Thank you.

Réponse acceptée

Star Strider
Star Strider le 16 Oct 2022
Try something like this —
C = [") injection-dr0015:138751)"
") injection-dr0015:68761)"
") injection-dr0015:122762)"
") injection-dr0015:83759)"
") injection-dr0015:163753)"];
E = str2double(extractBetween(C, ":",")"))
E = 5×1
138751 68761 122762 83759 163753
.
  2 commentaires
Mahdi Khademishamami
Mahdi Khademishamami le 16 Oct 2022
Thank you so much. It was great!
Star Strider
Star Strider le 16 Oct 2022
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 16 Oct 2022
Try this (one of several ways):
str = [") injection-dr0015:138751)"
") injection-dr0015:68761)"
") injection-dr0015:122762)"
") injection-dr0015:83759)"
") injection-dr0015:163753)"];
strNumbers = cell(numel(str), 1); % Use this if you want as character arrays
dblNumbers = zeros(numel(str), 1); % Use this if you want double numbers
for k = 1 : numel(str)
thisString = char(str(k));
index = strfind(thisString, ':') + 1;
% Use this if you want as character arrays:
strNumbers{k} = thisString(index : end-1);
% Use this if you want double numbers.
dblNumbers(k) = str2double(strNumbers{k});
end
strNumbers
strNumbers = 5×1 cell array
{'138751'} {'68761' } {'122762'} {'83759' } {'163753'}
dblNumbers
dblNumbers = 5×1
138751 68761 122762 83759 163753

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits


Version

R2021b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by