MATLABで文字列から頭字語を作成する簡単な方法はありますか?例えば:
'Superior Temporal Gyrus' => 'STG'
...関数REGEXPを使用できます:
str = 'Superior Temporal Gyrus'; %# Sample string
abbr = str(regexp(str,'[A-Z]')); %# Get all capital letters
...または、関数UPPERおよびISSPACEを使用できます。
abbr = str((str == upper(str)) & ~isspace(str)); %# Compare str to its uppercase
%# version and keep elements
%# that match, ignoring
%# whitespace
...または、代わりに大文字にASCII /UNICODE値を使用できます。
abbr = str((str <= 90) & (str >= 65)); %# Get capital letters A (65) to Z (90)
...関数REGEXPを使用できます:
abbr = str(regexp(str,'\w+')); %# Get the starting letter of each word
...または、関数STRTRIM、FIND、およびISSPACEを使用できます。
str = strtrim(str); %# Trim leading and trailing whitespace first
abbr = str([1 find(isspace(str))+1]); %# Get the first element of str and every
%# element following whitespace
...または、論理インデックスを使用して上記を変更し、 FINDの呼び出しを回避することができます。
str = strtrim(str); %# Still have to trim whitespace
abbr = str([true isspace(str)]);
...関数REGEXPを使用できます:
abbr = str(regexp(str,'\<[A-Z]\w*'));
ありがとう、これも:
s1(regexp(s1, '[A-Z]', 'start'))
文字列内の大文字で構成される省略形を返します。文字列は文の場合でなければならないことに注意してください