⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 coincidencecount.m

📁 loading a text file from a directory to your workspace in matlab
💻 M
字号:
%% Coincidence Counting Program

clear;
text1='ZYJKX RFSSP FIDSH PGLUC YDKCI RNRAA MCXDB QBBTQ TFXOF IMLQD NBXLM CXTXQ QNXDB RQFNI TFXON CKIFB THIIO DFHML QKRTK MOKSG XZAVZ IBSZY SIAIU XJKBX MLNAB XKCNS XMFSX IKYQD MPMXT OWTPI DOADB GQCGP VOFRJ CNVSS SVIVA CUTVX UFJET XDSTI LXABJ VTVPK RTKMO KSXGH QZJCW IZMJP LEZOF GECHO WHBSZ YKBTR UPJHM HQCYX GCFYR ETMZO KDKIJ KREEI OVFXF IPDMP MMFGF HLMYZ QNTQM DYTKS RMTBF SZCJC LIFRF ITRUC QPGHO YZAWR ADWJE IMMTC MMZOS ITRPD MDFEE TJUYI DCTCL PKBNR TPDOS SXVUX LDYXT OWTTW AXXUH VFRJT GXUBJ GXZAV ZIBSZ KWNXR FOWEK MEOJB ILMCN OXHFR JHXPR OAXWI ZDHWT VMMYT KSRDM TIVUX HXIPQ CFILX MUJ';

%% Remove the blanks from input spaces.

ind = find(text1 ~= ' ');
text = text1(ind);

%% 
len = length(text);
shmax = len-1;

count=0;
results = zeros(shmax,3);

for m=1:shmax
    
    % Rotate text relative to itself by m spots
    teststr=[text(m+1:end) text(1:m)];
    
    % Count number of matches
    for i=1:len
        if teststr(i)==text(i)
            count=count+1;
        end
    end
    
    results(m,1) = m;
    results(m,2) = count;
    
    % Normalize the count by the length of the string
    results(m,3) = count/len;
    
    % Reset count for next iteration
    count=0;
end


% What does this do?  Try to make sense of it!
results
max_m=find(max(results(:,3))==results(:,3))
max_norm_count=max(results(:,3))

f=find(results(:,2)>19);
results(f,:)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -