I want to create a function z=f(a,b)..how can I create like this using the below code?
1 回表示 (過去 30 日間)
古いコメントを表示
PLACEIUS NISHIGA G
2018 年 1 月 20 日
コメント済み: Walter Roberson
2018 年 1 月 20 日
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!