matlab - 如何解决 “Operands … must be convertible to logical scalar values” MATLAB错误消息?

标签 matlab image-processing syntax-error

在MATLAB中运行代码时,总是会收到此错误消息。我想进行模板匹配以识别字符。

  ??? Operands to the || and && operators must be convertible to logical scalar values.

  Error in ==> readLetter at 17
  if vd==1 || vd==2

我的代码是
  load NewTemplates % Loads the templates of characters in the memory.
  gambar = imresize(gambar,[42 24]); % Resize the input image 
  comp = [];
  for n = 1 : length(NewTemplates)
      sem = corr2(NewTemplates{1,n}, gambar); % Correlation with every image in the template for best matching.
      comp = [comp sem]; % Record the value of correlation for each template's character.
  end

  vd = find(comp == max(comp)); % Find index of highest matched character.

  % According to the index assign to 'letter'.
  if vd==1 || vd==2
      letter='A';

如何解决?

最佳答案

当comp包含多个具有最大值的元素时,find()返回一个 vector 。

看到这个:

a = [1:5 5];
index = find(a==max(a)); % index =  5  6
numel(index) % ans = 2

因此,请使用max函数而不是find 或仅使用第一个匹配项。

关于matlab - 如何解决 “Operands … must be convertible to logical scalar values” MATLAB错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18045956/

相关文章:

MATLAB sin() 与 sind()

android - 是否有适合在已知环境中识别物体的图像处理库/AR 技术?

image - 直方图均衡结果

php - 意外的其他情况(T_ELSE)

perl - 在散列元素中使用未初始化的值 $_

matlab - matlab中二分图的连通分量

c++ - 仅在使用 -Wl,-rpath,/usr/local/MATLAB/R2014b/bin/glnxa64 添加 Matkab 代码后出现链接错误 OpenCV

javascript - 在 javascript 中使用 blob 写入时文件开头出现意外字符

c++ - 调用 : const pointer to pointer 没有匹配函数

方案 - 无法在空句法环境中绑定(bind)名称 : tmp