Help me plot my first function, please
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Walter Roberson
2017-2-13
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.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!