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

2 次查看(过去 30 天)
I get an operators error... Not sure why. Can you help out?
Here is the code:
while count<=i
mfg=G(count)
if mfg == 27 && mfgdate2 >= 1946 && mfgdate<= 1974 || mfg == 27 && mfgdate>= 1983 && mfgdate<= 1988
MfgScore(count,:)=3;
end
count=count+1;
end

采纳的回答

Walter Roberson
Walter Roberson 2017-11-13
Either mfgdate or mfgdate2 are not scalar. You probably need to index them with count
It is suspicious that you use mfgdate2 only once in the expression

更多回答(1 个)

Faustino Quintanilla
Fixed by adding count to elseif statement:
while count<=i
mfg=G(count);% Priority idnetifier
if mfg == 15
MfgScore(count,:)=5;
elseif mfg == 20
MfgScore(count,:)=5;
elseif mfg == 8 && mfgdate2(count)>= 1967 && mfgdate2(count)<= 1998
MfgScore(count,:)=4;
elseif mfg == 9 && mfgdate2(count)>= 1960 && mfgdate2(count)<= 1971
MfgScore(count,:)=2;
elseif mfg == 27 && mfgdate2(count)>= 1946 && mfgdate(count)<= 1974 || mfg == 27 && mfgdate(count)>= 1983 && mfgdate(count)<= 1988
MfgScore(count,:)=3;
elseif mfg == 1 && mfgdate2(count)>= 1949 && mfgdate2(count)<= 1969
MfgScore(count,:)=5;
elseif mfg == 13 && mfgdate2(count)>= 1963 && mfgdate2(count)<= 1964
MfgScore(count,:)=2;
elseif mfg == 19 && mfgdate2(count)>= 1962 && mfgdate2(count)<= 1967
MfgScore(count,:)=2;
end
count=count+1;
end
  1 个评论
Walter Roberson
Walter Roberson 2017-11-13
I find it suspicious that
elseif mfg == 27 && mfgdate2(count)>= 1946 && mfgdate(count)<= 1974 || mfg == 27 && mfgdate(count)>= 1983 && mfgdate(count)<= 1988
is the only place that uses mfgdate instead of mfgdate2, and that in the middle of the expression mfgdate2 is the lower bound but mfgdate is the upper bound. It would make more sense to me if you had
elseif mfg == 27 && mfgdate2(count)>= 1946 && mfgdate2(count)<= 1974 || mfg == 27 && mfgdate(count)>= 1983 && mfgdate(count)<= 1988

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by