matlab逻辑与运算问题 5
x=linspace(0,2*pi,M);y1=sin(x);y2=cos(x);count=0;%计数变量fori=1:1:4096%y2过Th时if(y2(1:i)=...
x=linspace(0,2*pi,M);
y1=sin(x);
y2=cos(x);
count=0;%计数变量
for i=1:1:4096
%y2过Th时
if (y2(1:i)==(sqrt(2)/2))&&(0<=y1(1:i))
count =count+1;
elseif (y2(1:i)==(sqrt(2)/2))&&(y1(1:i)<0)
count=count-1;
%y2过T1时
elseif (y2(1:i)==(-sqrt(2)/2))&&(y1(1:i)<0)
count=count+1;
elseif (y2(1:i)==(-sqrt(2)/2))&&(0<=y1(1:i))
count=count-1;
end
end
结果是:
??? Operands to the || and && operators must be convertible to logical scalar values.
为什么? 展开
y1=sin(x);
y2=cos(x);
count=0;%计数变量
for i=1:1:4096
%y2过Th时
if (y2(1:i)==(sqrt(2)/2))&&(0<=y1(1:i))
count =count+1;
elseif (y2(1:i)==(sqrt(2)/2))&&(y1(1:i)<0)
count=count-1;
%y2过T1时
elseif (y2(1:i)==(-sqrt(2)/2))&&(y1(1:i)<0)
count=count+1;
elseif (y2(1:i)==(-sqrt(2)/2))&&(0<=y1(1:i))
count=count-1;
end
end
结果是:
??? Operands to the || and && operators must be convertible to logical scalar values.
为什么? 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询