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

1 次查看(过去 30 天)
Hi ,
I wrote this function:
function [flag_SO_Sell,flag_SO_Buy,flag_SO_Hold]= SO_Sub_Rule(Sthochestic_Osilator,High_SO,Low_SO)
% function [flag_SO_Sell,flag_SO_Buy]= SO_Sub_Rule(Sthochestic_Osilator,High_SO,Low_SO)
%%SO Rule
% Need to add for loop with index
% Sthochestic_Osilator([1:end],2)=Sthochestic_Osilator([]);
for i=1:length(Sthochestic_Osilator)
if Sthochestic_Osilator > High_SO
% 'Sell'
flag_SO_Sell=-1;
else if Sthochestic_Osilator < Low_SO
% 'Buy'
flag_SO_Buy=1;
else if (Sthochestic_Osilator > Low_SO) && (Sthochestic_Osilator < High_SO)
flag_SO_Hold=0 ;
% % disp ('Hold')
end
end
end
end
with any idea why i got this error from matlab in the command line: Operands to the and && operators must be convertible to logical scalar values.
Error in SO_Sub_Rule (line 13) else if (Sthochestic_Osilator > Low_SO) && (Sthochestic_Osilator < High_SO)
can someone tell what does this error mean?

回答(1 个)

Preethi
Preethi 2016-12-1
hi,
the output of < and > gives a vector since Sthochestic_Osilator is a vector. When using short circuit operators like '&&' the operators should be scalar. Using binary '&' in place of '&&' may help

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by