Help me plot my first function, please
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello. I'm a complete beginner when it comes to MATLAB and couldn't find a question that helped me. (Probably because I don't know the right terms to search). Sorry.
Why can't I plot this function? It worked on a smaller scale in a test file i made.
I get error: "Undefined function or variable 'r'." But I defined it in the function.
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
B = (on * (ex/tx)*WLn)
fplot(r)
function r = In(Vsn)
r = B*(1.2 - Vn - (Vsn/2))*Vsn
end
0 commentaires
Réponse acceptée
Walter Roberson
le 13 Fév 2017
You could use:
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
B = (on * (ex/tx)*WLn);
r = @(Vsn) B*(1.2 - Vn - (Vsn/2)).*Vsn;
fplot(r)
The above can be used as a script file.
Any variable that you define in a function only exists while the function is executing.
You were not executing the function named In at all.
Also, your function used values that were defined in the script and not passed into the function.
You could also have used
function my_first_plot
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
fplot(@In)
function r = In(Vsn)
r = B*(1.2 - Vn - (Vsn/2))*Vsn
end
end
This is a more advanced program that shares variables with a nested function.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Graphics Objects dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!