我有一个大约 9000 个小写单词的文本文件。我想找到每个单词中最后一个字母的概率(字母频率/单词数)。
这是我的第一次尝试:
function [ prma ] = problast()
counts = zeros(1,26);
%refer to cell index here to get alphabetic number of char
s = regexp('abcdefghijklmnopqrstuvwxyz','.','match');
f = fopen('nouns.txt');
ns = textscan(f,'%s');
fclose(f);
%8960 is the length of the file
for i =1:8960
c = substr(ns(i),-1,1);
num = find(s == c);
counts(num) = num;
end
prma = counts / 8960;
disp(prma);
这给了我这个错误:
Undefined function 'substr' for input arguments of type 'cell'.
有任何想法吗?