Function runs in one script but not another ?
显示 更早的评论
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
回答(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
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
