Displaying string with variables

조회 수: 1 (최근 30일)
Rick
Rick 2015년 11월 9일
댓글: Walter Roberson 2015년 11월 9일
Hello,
I'm trying to make a function that tell me the coefficients x,y, and z for a given n,a,b,c,d CnHaObNcSd + xH2O ---> yCH4 + zCO2 + cNH3 + dH2S
And return at output with a sentence
function ChemicalFormula = foodwastes(n,a,b,c,d)
x = n - a/4 - b/2 + 3/4*c + d/2;
y = n/2 + a/8 - b/4 - 3/8*c - d/4;
z = n/2 - a/8 + b/4 + 3/8*c + d/4;
display([' C ',num2str(n), 'H' ,num2str(a), ' O ' ,num2str(b), ' N ' ,num2str(c), ' S ' ,num2str(d),
' + ' ,num2str(x), ' H_{2}O \rightarrow ',num2str(y), ' CH_{4} + ' ,num2str(z), ' CO_{2} + ' ,num2str(c),
' NH_{3} + ' ,num2str(d), ' H_{2}S '])
MW = 16*n + 1*a + 16*b + 14*c + 32*d;
diplay(['Food Waste Molecular weight is ' num2str(MW)]);
However, I keep getting this error
Undefined function 'foodwastes' for input
arguments of type 'double'.
Any ideas what I can do to fix this? Thanks
  댓글 수: 1
Walter Roberson
Walter Roberson 2015년 11월 9일
Are you storing the code in foodwastes.m in a directory that is on your MATLAB path?

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by