在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/