Create multiple sub arrays in one line!
显示 更早的评论
Hi everyone, I have the string bellow as input to a function
'(44) (hello) (good) ()'
the function looks for indices positions of left and right parenthesis...
open = strfind(text, '(');
close = strfind(text, ')');
after that I want to isolate everything inside the parenthesis...
I was hoping there was a fast way of doing this something like:
output = text(open:close);
but it doesn't seem to work does anyone has a clue if this is possible?!
采纳的回答
更多回答(1 个)
Turlough Hughes
2019-11-27
编辑:Turlough Hughes
2019-11-27
This is one way to go about it:
a=strsplit(text(text~=' '),{'(',')'})
output=sprintf('%s',a{:})
1 个评论
Turlough Hughes
2019-11-27
编辑:Turlough Hughes
2019-11-27
Actually, just realising you could also write:
output=text(text~=' ' | text~='(' | text~=')')
类别
在 帮助中心 和 File Exchange 中查找有关 Entering Commands 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!