Function runs in one script but not another ?
Show older comments
working on a function about concentration, works fine in its own script conc.m but when i cpoy and paste to another script where i need it it doesn't plot a graph.
heres the function:
function[] = conc()
v = 0.00001 ;
D = 0.0000001 ;
t = 86400 ;
X = 0 : 0.01 : 2 ;
C = (1/(sqrt(4*pi*D*t)))*exp((-(X-v*t).^(2))/(4*D)) ;
plot (X, C, 'r-')
title ('Concentration of substance with respect to distance from source')
xlabel ('distance from source, m')
ylabel ('concentration, mol/l')
end
any help much appreciated
Answers (1)
Vectorise its calculation, then call it —
conc
function[] = conc()
v = 0.00001 ;
D = 0.0000001 ;
t = 86400 ;
X = 0 : 0.01 : 2 ;
C = (1/(sqrt(4*pi*D*t))).*exp((-(X-v.*t).^(2))/(4*D)) ;
plot (X, C, 'r-')
title ('Concentration of substance with respect to distance from source')
xlabel ('distance from source, m')
ylabel ('concentration, mol/l')
end
Categories
Find more on MATLAB 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!