filter string in the string
23 次查看(过去 30 天)
显示 更早的评论
Hello,
I am quietly new with matlab script.
I have a string as example.
str = 'this matlab is a good software, it is a version 9.4 which is equal to 2018a'
objective, I want to filter the number from that string ( so it is "9.4").
Note that I cannot see that number. All i want is to scan that number and show in my workspace.
so the scribt should read the text and identify the number of the version and show in my workspace.
I appreciate your help.
Regards,
LN
2 个评论
Ted Shultz
2019-8-21
Do you not want to also get '2018'? What rule would the code use to exclude this?
Adam
2019-8-21
doc regexp
should help do this. It takes a bit of getting used to parameterising regular expressions though. There are likely simpler ways depending how robust you want it to be.
采纳的回答
Stephan
2019-8-21
编辑:Stephan
2019-8-21
str = 'this matlab is a good software, it is a version 9.4 which is equal to 2018a'
str = char(str);
idx = find((uint8(str)>=48 & uint8(str)<=57) | uint8(str)==46 | uint8(str)==32);
res = split(string(str(idx))," ");
res(res=="")=[]
The second line makes sure that it also works with:
str = "this matlab is a good software, it is a version 9.4 which is equal to 2018a"
更多回答(2 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Import and Export 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!