如果ind == 1 ||,我不会在写if-else语句的地方使用它ind == 2它在比较什么,它如何说如果等于1或2,则等于字母A,如果等于3或4,则等于B,等等。有人可以帮我吗? if-else语句如何随机给出任何数字,或者所比较的数字具有一定意义?
%这是从主文件调用的函数。
function letter=readLetter(snap)
load NewTemplates
snap=imresize(snap,[42 24]);
rec=[ ];
for n=1:length(NewTemplates)
cor=corr2(NewTemplates{1,n},snap);
rec=[rec cor];
end
ind=find(rec==max(rec));
display(ind);
% Alphabets listings.
if ind==1 || ind==2
letter='A';
elseif ind==3 || ind==4
letter='B';
elseif ind==5
letter='C';
elseif ind==6 || ind==7
letter='D';
elseif ind==8
letter='E';
elseif ind==9
letter='F';
``` like so up to Z and 0 -9 ```
end
end
答案 0 :(得分:0)
在Matlab中,运算符可以写为||
。例如,您的情况:
if ind==1 || ind==2
letter='A';
均值:如果ind
等于1
或ind
等于2
-执行指令(将letter
变量设置为{{1} }。
不过,在这种情况下,'A'
更具意义。例如:
switch
答案 1 :(得分:0)
经过一些调试,我得到了答案。被比较的值来自由MATLAB创建的.mat文件,用于存储图像的二进制文件。 1 2 3 ...是.mat文件中存储的各个字母的列。我将二进制文件转换为图像,这是正确的。