开发者

Matlab Correlation Function

function letter=read_char(imgn, num_letters)

global templates

comp=[ ];

for n=1:num_letters

    sem=corr2(imgn, templates{1,n});

    comp=[comp sem];

end

vd=find(comp==max(comp));

Can someon please explain what the 'FOR' loop does and how 'vd' 开发者_Go百科is calculated? Also, what is the variable 'comp' and what will it looks like as the array also contains itself and another variable 'sem' which is calculated from the corr2 function. thanks


The for loop creates a loop variable n that starts at 1 for the first loop and is incremented by 1 for each successive loop until it reaches num_letters. This means the loop will execute num_letters times.

The variable comp is first initialized to the empty matrix []. Within the loop, a 2-D correlation coefficient is computed between the matrix imgn and another matrix templates{1,n} (indexed from a cell array) using the function CORR2. The correlation coefficient sem is appended to the array comp using horizontal concatenation. This will ultimately result in comp being a 1-by-num_letters array of correlation coefficients.

The variable vd stores the array indices where values in comp are equal to the maximum value found in comp. This is done using the functions MAX and FIND and the comparison operator ==.

In the future, I would urge you to first use the online documentation to try and help you better understand how MATLAB works. It is very good documentation. I've learned most of what I know from it. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜