私は、テキストファイル 'in'が与えられ、4文字すべてが '****'に置き換えられたファイルを返す関数を持っています。今まで私は各セルが1ワードである3d配列を得ることができました。 4文字の単語をすべて「****?」にするにはどうすればいいですか?Matlab 3次元配列で正規表現を使用するには?
%in.txt =
%word words
%words words words word
%words
%word word word
fid = fopen(in);
tline = fgetl(fid);
string = {''};
while ischar(tline)%create an array where each cell is 1 line
string(length(string)+1) = {tline};
tline = fgetl(fid);
end
str = {''};
for x=2:length(string)%create a matrix where each cell is is 1 line with each of those cells being 1 word
str(x) = {split(string(x), ' ')};
end
end
使用 'のregexprep(STR、 '\ <-ZA-Z] {4} \>'、 '****')' – obchardon