I'm trying to make a function and my if statement isn't working properly
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I'm trying to make a function to create unit steps. I think I have it almost working but for some reason it wont execute the if statement that is inside my for loop. It goes straight to the else statement and executes y = 0 across the time values when I plot them. I'm trying to find out why it wont go to one when a >= mu. I've been looking on the internet to find something but I cant seem to. Thanks.
function y = my_unit_step(t,mu)
a = t;
y = length(a); % y outputs same size as t
for i = 1:length(a)
if a >= mu
y(i)=1;
else
y(i)=0;
end
end
plot (t,y)
0 个评论
采纳的回答
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!