I'm trying to write a simple function that takes two inputs, x
and y
, and passes these to three other simple functions that add, multiply, and divide them. The main function should then display the results as a string containing x
, y
, and the totals.
I think there's something I'm not understanding about output arguments. Anyway, here's my (pitiful) code:
function a=addxy(x,y)
a=x+y;
function b=mxy(x,y)
b=x*y;
function c=dxy(x,y)
c=x/y;
The main function is:
function [d e f]=answer(x,y)
d=addxy(x,y);
e=mxy(x,y);
f=dxy(x,y);
z=[d e f]
How do I get the values for x
, y
, d
, e
, and f
into a string? I tried different matrices and stuff like:
['the sum of' x 'and' y 'is' d]
but none of the variables are showing up.
Two additional issues:
- Why is the function returning "ans 3" even though I didn't ask for the length of
z
? - If anyone could recommend a good book for beginners to MATLAB scripting I'd really appreciate it.