Transforming a string of letters into number based on each value equaling a number.
5 次查看(过去 30 天)
显示 更早的评论
If there are a finite amount of variables available for a string like... a,b,c,d,e....z, and each value is numbered 1,2,3,4,5....26, how can I write a short code to take in a string of letters like "bccddee" and get an output of "2+3+3+4+4+5+5".
I can define each letter as a number, but the 1st problem I encounter is braking up the string into a finite amount of values (7) it contains and then using a loop to go trough them inside the string and add them to the total.
Anyone know how to do this or atleast can point me towards the direction of how I can get within a letter string and convert it to numbers which then i can add?
0 个评论
回答(4 个)
tban
2017-9-20
1 个评论
John Chilleri
2017-9-20
Glad it's working, but I don't think you need to use char:
>> length('abcdef')
ans =
6
(works in my command window).
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Whos 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!