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

 채택된 답변

Star Strider
Star Strider 2021년 4월 30일

0 개 추천

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

Ferdinand Leng
Ferdinand Leng 2021년 4월 30일
Brilliant, solved thank you!
Star Strider
Star Strider 2021년 4월 30일
Thank you!
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

릴리스

R2020b

질문:

2021년 4월 30일

댓글:

2021년 4월 30일

Community Treasure Hunt

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

Start Hunting!

Translated by