Can we sum lastletter of string?

1 visualización (últimos 30 días)
NGÔ LÝ NGUYÊN
NGÔ LÝ NGUYÊN el 15 de Feb. de 2020
Comentada: NGÔ LÝ NGUYÊN el 15 de Feb. de 2020
i have data with
A = 111n22
B = 444m11
C = 777n55
I want select last letter of A B and C and then sum it. Pls help me!

Respuesta aceptada

Stephen23
Stephen23 el 15 de Feb. de 2020
>> A = '111n22';
>> B = '444m11';
>> C = '777n55';
>> sum(str2double(regexp({A,B,C},'\d$','match','once'))) % single
ans = 8
Or perhaps:
>> sum(str2double(regexp({A,B,C},'\d+$','match','once'))) % multiple
ans = 88

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by