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

1 回表示 (過去 30 日間)
Moshe
Moshe 2016 年 12 月 1 日
回答済み: Preethi 2016 年 12 月 1 日
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 Center および File ExchangeMATLAB についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by