what is wrong with this code

11 ビュー (過去 30 日間)
JJ
JJ 2021 年 4 月 28 日
回答済み: Image Analyst 2021 年 4 月 28 日
figure
x=0:0.01:2;
plot(conc,x,'r-')
xlabel('distance from the source (m)')
ylabel('concentration (mol/l')
title('the concentration of a substance with distance from initial source')
Error using CES_StudentID_empty>conc
Too many output arguments.
Error in CES_StudentID_empty (line 48)
plot(conc,x,'r-')
  3 件のコメント
Walter Roberson
Walter Roberson 2021 年 4 月 28 日
We should suspect from the code and error that conc is not a variable, and is instead a function that is defined as not returning any output.
Image Analyst
Image Analyst 2021 年 4 月 28 日
What is that? That's a script, not a function.

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2021 年 4 月 28 日
Try this:
% Demo by Image Analyst.
clc; % Clear the command window.
fprintf('Beginning to run %s.m ...\n', mfilename);
close all; % Close all figures (except those of imtool.)
clearvars;
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 16;
t=86400;
v=10.^-5;
D=10.^-7;
x=0:0.01:2;
%Calcuate the concentration in ( mol/l)
conc = (1./sqrt(4 * pi * D * t)* exp(-1 * ((x - v * t) .^ 2 ./ 4 * D )));
plot(conc, x, 'r-', 'LineWidth', 3)
grid on;
xlabel('Distance from the source (m)', 'FontSize', fontSize)
ylabel('Concentration (mol/l', 'FontSize', fontSize)
title('The concentration of a substance with distance from initial source', 'FontSize', fontSize)
fprintf('Done running %s.m\n', mfilename);

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2021 年 4 月 28 日
You currently have
t=86400;
v=10.^-5;
D=10.^-7;
x=0:0.01:2;
%Calcuate the concentration in ( mol/l)
conc=(1./sqrt(4 * pi * D * t)* exp(-1 * ((x - v * t) .^ 2 ./ 4 * D )));
stored in conc.m . Rename that file to calculate_conc.m . Then
figure
calculate_conc;
plot(conc,x,'r-')
xlabel('distance from the source (m)')
ylabel('concentration (mol/l')
title('the concentration of a substance with distance from initial source')

カテゴリ

Help Center および File ExchangeMATLAB Report Generator についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by