# How to extract number from this string cell?

11 views (last 30 days)
Mahdi Khademishamami on 16 Oct 2022
Commented: Star Strider on 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.

Star Strider on 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 CommentsShow 1 older commentHide 1 older comment
Star Strider on 16 Oct 2022
As always, my pleasure!

Image Analyst on 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
Mahdi Khademishamami on 16 Oct 2022
Thank you so much!

### Categories

Find more on Characters and Strings in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!