Trying to plot, no figure comes up

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

 Accepted Answer

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 Comments

Brilliant, solved thank you!
Thank you!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Release

R2020b

Community Treasure Hunt

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

Start Hunting!