Create multiple sub arrays in one line!
11 ビュー (過去 30 日間)
古いコメントを表示
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?!
0 件のコメント
採用された回答
Star Strider
2019 年 11 月 27 日
Try this:
str = '(44) (hello) (good) ()';
out = regexp(str, '(?<=\()\w*(?=\))', 'match')
producing:
out =
1×3 cell array
{'44'} {'hello'} {'good'}
Make appripriate changes to get the result you wannt.
4 件のコメント
その他の回答 (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~=')')
参考
カテゴリ
Help Center および File Exchange で Entering Commands についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!