Making IF conditional sentance.
显示 更早的评论
Hi guys. I want to make some if conditional sentance.
I can't get a result, because of 'f'.
-----------------------------------------------------
f=[0:1:20]
f1=10;
E=20;
B0=15;
if (0<f && f<f1);
P = sqrt(E)/(2*B0);
elseif (f1<f && f<2*B0-f1);
P = (sqrt(E)/(4*B0))*(1+cos((pi*(abs(f)-f1))/(2*(B0-f1))));
else
P = 0
end
plot(f,2*B0*P/sqrt(E));
-----------------------------------------------------------------
Matlab says that && can't be used with doubled value..
Please help.
采纳的回答
更多回答(1 个)
James Tursa
2015-4-2
编辑:James Tursa
2015-4-2
0 个投票
f is a vector, so the expression f<f1 is also a vector. And when you try to use this vector with the && operator you get the error message.
Either vectorize all of this to generate your P if you are up to the task, or wrap it in a loop to generate your P values using only one element of f in each iteration to generate one element of P.
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!