Calling functions from different scripts
Show older comments
%func.m function f=transs(alpha) f=exp(-alpha)+alpha-1 end
i wrote this function in a script,but when i try calling it in another script using transs(theta),it keeps giving me an error saying alpha is not defined, i called func.m by writing func; in the code,why am i getting this error. func.m works through the command window though.The following is the second script i wrote calling func.m.
init1; func; theta=1:0.5:20 H11=zeros(1,numel(theta)); H12=zeros(1,numel(theta)); H21=zeros(1,numel(theta)); H22=zeros(1,numel(theta));
data= zeros(1,numel(theta)); for i=1:numel(theta) H11(i)=(theta(i)^2)/2-transs(theta(i)); H12(i)=(theta(i)^2)/2-transs(theta(i)); H21(i)=(theta(i)^2)/(2*epsilon1)-(epsilon1*transs(theta(i)/epsilon1)); H22(i)=(theta(i)^2)/(2*epsilon2)-(epsilon2*transs(theta(i)/epsilon2)); end
Accepted Answer
More Answers (0)
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!