Displaying string with variables

2 次查看(过去 30 天)
Rick
Rick 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 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by