Matlab相关函数
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));
有人可以解释一下“FOR”循环的作用以及“vd”是如何计算的吗? 另外,变量“comp”是什么以及它看起来是什么样子,因为数组还包含其自身和另一个从 corr2 函数计算得出的变量“sem”。 谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
for 循环 创建循环变量
n
第一个循环从 1 开始,每个后续循环加 1,直到达到num_letters
。这意味着循环将执行num_letters
次。变量comp首先被初始化为空矩阵 <代码>[]。在循环内,计算矩阵
imgn
和另一个矩阵templates{1,n}
(从 元胞数组) 使用函数 CORR2。使用 sem 附加到数组comp
rel="nofollow">水平串联。这最终将导致comp
成为 1×num_letters
相关系数数组。变量
vd
存储数组索引,其中comp
中的值等于comp
中找到的最大值。这是使用函数 MAX 和 FIND 和 比较运算符==
。将来,我强烈建议您首先使用在线文档来尝试帮助您更好地了解 MATLAB 的工作原理。这是非常很好的文档。我从中学到了大部分知识。 ;)
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 reachesnum_letters
. This means the loop will executenum_letters
times.The variable
comp
is first initialized to the empty matrix[]
. Within the loop, a 2-D correlation coefficient is computed between the matriximgn
and another matrixtemplates{1,n}
(indexed from a cell array) using the function CORR2. The correlation coefficientsem
is appended to the arraycomp
using horizontal concatenation. This will ultimately result incomp
being a 1-by-num_letters
array of correlation coefficients.The variable
vd
stores the array indices where values incomp
are equal to the maximum value found incomp
. 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. ;)