How do I find a value in a vector and then create a new vector with those value?
Show older comments
I am having an issue with the following task. How do I create a vector that shows the position of the alphabetic characters as numerical values? Create a vector Alphas that has the numeric positions of all alphabetic characters in TS1. For Example: TS1='%@3Gb6' returns Alphas=[4 5]. I am using the Matlab R2015b software.
Accepted Answer
More Answers (1)
Star Strider
on 20 Jan 2016
This is one possibility:
TS1='%@3Gb6';
[AlphaSt,AlphaEnd] = regexp(TS1, '[A-Za-z]+')
AlphaSt =
4
AlphaEnd =
5
2 Comments
Guillaume
on 20 Jan 2016
Actually, the simpler regex
pos = regexp(TS1, '[A-Za-z]');
would work better for the OP purpose.
Star Strider
on 20 Jan 2016
Thank you, Guillaume. I’m still learning the best ways to use regexp, and with your demonstrated expertise on this and several other topics, I value your Comments.
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!