I want to create a function z=f(a,b)..how can I create like this using the below code?
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
PLACEIUS NISHIGA G
il 20 Gen 2018
Commentato: Walter Roberson
il 20 Gen 2018
if true
a=Ns;
b=8;
if ~mod(a,b)
z=0
else
z=b-mod(a,b);
end
end
0 Commenti
Risposta accettata
Image Analyst
il 20 Gen 2018
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 Commenti
Walter Roberson
il 20 Gen 2018
If you are using R2016a or earlier, you will need to store the code starting from 'function' in the file f.m
Più risposte (1)
Walter Roberson
il 20 Gen 2018
The calculation simplifies.
f = @(a,b) mod(-a, b);
This applies even for negative a
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!