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

2 views (last 30 days)
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?

Answers (1)

Preethi
Preethi on 1 Dec 2016
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

Categories

Find more on MATLAB in Help Center and File Exchange

Tags

Products

Community Treasure Hunt

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

Start Hunting!