Borrar filtros
Borrar filtros

How to extract number from this string cell?

89 visualizaciones (últimos 30 días)
Mahdi Khademishamami
Mahdi Khademishamami el 16 de Oct. de 2022
Comentada: Star Strider el 16 de Oct. de 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.

Respuesta aceptada

Star Strider
Star Strider el 16 de Oct. de 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 comentarios
Mahdi Khademishamami
Mahdi Khademishamami el 16 de Oct. de 2022
Thank you so much. It was great!
Star Strider
Star Strider el 16 de Oct. de 2022
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de Oct. de 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

Categorías

Más información sobre MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by