I am trying to call another function(add) from within my code but i get the following error. Can any one please help.
a=[1 2 3 4 5 6]
[b]=add(a)% the commands of add actually produces d
c=a+d
??? Undefined function or variable "d".

1 Kommentar

Jan
Jan am 18 Mai 2011
You could show us the code of "add" to clarify what "actually produces d" means.

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Sean de Wolski
Sean de Wolski am 18 Mai 2011

1 Stimme

No. The command add may produce 'd' in its own function workspace, but when it is retrieved it is called 'b' because that's the variable name you're assigning it to.
Did you want:
d = add(a); ?
Or did you want add to put a d in your workspace?
doc assignin

3 Kommentare

God'sSon
God'sSon am 18 Mai 2011
thank you for your answer. Also, how do I use another variable eg; 'f' which is also produced somewhere inside the function before d is produced. ie; I want to use both 'd' and 'f' produced inside [b].
Sean de Wolski
Sean de Wolski am 18 Mai 2011
function [f d] = add(x)
%do stuff with x to create f and d; e.g.
f = x*pi
d = 11./x
call add with
[f d] = add(a)
or whatever.
doc function for a good description of how they work
God'sSon
God'sSon am 19 Mai 2011
This works fine. Thank you.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by