Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

having neural networks as arguments

Asked by Respaco on 27 Jun 2013

Hi, I had previously asked this question : "Hi, My question is about the way functions are used and how to send arguments to them properly. Look at this part of a code for instance:

My function Fitt has just one output and the 'x' dimension is 4*1. In the function i refer to a function that gets artificial neural networks as input. As i try to run the code, the line contain the function doesnt work and it leads to error. I cant understand why it could not go through the function. I thought it is perhaps because the Fitt function should include neural networks as argument.Is that true? I must include them? I prefer i could not increase Fitt function arguments ...

Also i had made the networks before and before running this code, i opened them in my workspace. That's why i find the error very weird.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function sum =Fitt(x)

inp =QECsimull(net1,net2,t1s,t2s,x); ... sum=T; end %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Dear Dpb told me to change the sum name first and then include the networks in the arguments. As Fitt was a function in my main function Optiz. I decided to include the networks as the arguments of the main program so all the subfunctions will understand it. So i changed the main function like:

function Optiz(net1,net2,t1s,t2s) Fitt(x); ... %%%%%%%%%%%%%%%%%%%% function mysum =Fitt(x)

inp =QECsimull(net1,net2,t1s,t2s,x); ... mysum=T; end %%%%%%%%%%%%%%%%%%%%

But again the error says undefined function or variable net1 (though exists inthe workspace and works!)!!

Any suggestions?

Thanks

1 Comment

Greg Heath on 8 Jul 2013

Inside of Fitt, the function only knows x and whatever variables are declared global in Optiz.

Respaco

Products

No products are associated with this question.

1 Answer

Answer by Greg Heath on 28 Jun 2013
Accepted answer

A function has access to external functions only through the parameter list or if they are declared global. In spite of your predilections, use the former.

Hope this helps.

Thank you for formally accepting my answer

Greg

0 Comments

Greg Heath

Contact us