I want to create a function z=f(a,b)..how can I create like this using the below code?
2 次查看(过去 30 天)
显示 更早的评论
if true
a=Ns;
b=8;
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
end
0 个评论
采纳的回答
Image Analyst
2018-1-20
MATLAB documentation tells you how to make functions. Like, to make your "f" function you'd do this:
function z = f(a, b)
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
To call it, you'd do this:
a = Ns;
b = 8;
z = f(a, b)
4 个评论
Walter Roberson
2018-1-20
If you are using R2016a or earlier, you will need to store the code starting from 'function' in the file f.m
更多回答(1 个)
Walter Roberson
2018-1-20
The calculation simplifies.
f = @(a,b) mod(-a, b);
This applies even for negative a
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!