gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 08:09:11 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com