How to extract number from this string cell?

65 次查看(过去 30 天)
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
Star Strider 2022-10-16
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
.

更多回答(1 个)

Image Analyst
Image Analyst 2022-10-16
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by