Function runs in one script but not another ?
Afficher commentaires plus anciens
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
Réponses (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
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
