Hi, I'm trying to plot a figure, however when I press 'Run Code' no plot comes up - I've input the same code into the command window and it worked, also into a new program and a figure came up no problem, however when I try to run this code as a section (part of a school assignment) nothing comes up - even if I add a line of code that is meant to be provide an error (eg just ffffff), still no error comes up and nothing runs, could someone please help? Relevent code below
function [] = conc ()
% Set the values for the equation
t = 86400 ;
x = [ 0: 0.02 : 2 ] ;
v = 10^-5 ;
D = 10^-7 ;
% Input the equation
c = (1/ sqrt(4 * pi * D * t )) * exp( - ((x) - (v * t)).^2 / 4*D) ;
% Plot the figure, labelling title + axis and setting limits for a suitable
% scale
figure(1) ;
plot(x, c, 'r-') ;
ylabel('Concentration (m^2/s)') ;
xlabel('Distance from the Source (m)') ;
title ('The concentration of a substance with distance from an initial source') ;
xlim ([0 2]) ;
end

 Respuesta aceptada

Star Strider
Star Strider el 30 de Abr. de 2021
I suspect that the problem is that you simpoly need to call it correctly. The function must be at the end of the file, if it is in the same file you are calling it in, so call it before defining it —
conc
ans = 1×101
3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349 3.0349
function [c] = conc ()
% Set the values for the equation
t = 86400 ;
x = [ 0: 0.02 : 2 ] ;
v = 10^-5 ;
D = 10^-7 ;
% Input the equation
c = (1./ sqrt(4 * pi * D * t )) * exp(-((x) - (v * t)).^2 / 4*D) ;
% Plot the figure, labelling title + axis and setting limits for a suitable
% scale
figure(1) ;
plot(x, c, 'r-') ;
ylabel('Concentration (m^2/s)') ;
xlabel('Distance from the Source (m)') ;
title ('The concentration of a substance with distance from an initial source') ;
xlim ([0 2]) ;
end
.

2 comentarios

Ferdinand Leng
Ferdinand Leng el 30 de Abr. de 2021
Brilliant, solved thank you!
Star Strider
Star Strider el 30 de Abr. de 2021
Thank you!
As always, my pleasure!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2020b

Etiquetas

Preguntada:

el 30 de Abr. de 2021

Comentada:

el 30 de Abr. de 2021

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by