Is it possible to use logical indexing to specify between a number interval and include a value outside that interval.
1 回表示 (過去 30 日間)
古いコメントを表示
Confidential Confidential
2019 年 1 月 31 日
回答済み: Steven Lord
2019 年 1 月 31 日
I'm trying to use logical vectoring to exclude certain characters by using a mask on a string. So say I had a string like str='This !is @tes#t'. I'm trying to get "This is test". I'm donig this by converting the strings to doubles and then setting all characters to upper. Finally creating a mask that is between 65 and 90. I also need the mask to include 32 so I can keep spaces between words. How can I include that? Alternatively is there a better way to only include the alphabetic characters in a mask?
str='This !is @tes#t'
Ustr=upper(str)
Mask = 65<=Ustr & Ustr<=90
0 件のコメント
採用された回答
James Tursa
2019 年 1 月 31 日
編集済み: James Tursa
2019 年 1 月 31 日
E.g.,
Mask = ismember(str,[' ','a':'z','A':'Z']);
Or using your method
Mask = (65<=Ustr & Ustr<=90) | Ustr == 32;
その他の回答 (1 件)
Steven Lord
2019 年 1 月 31 日
You could use the isstrprop function to keep alphabetic letters and whitespace characters.
str='This !is @tes#t';
letters = isstrprop(str, 'alpha');
spaces = isstrprop(str, 'wspace');
str(letters | spaces)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!