Got Questions? Get Answers.
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

Thread Subject:
Nested Functions Help

Subject: Nested Functions Help

From: Don

Date: 12 Oct, 2010 08:43:03

Message: 1 of 3

Say for instance I have a function x which when I call I want to display all the other functions I have written within the .m file


function x = SequenceConverge(e,f,g,h)


e = function a
    
    f = function b
        
        g = function c
            
            h = function d
                
                end

function d()
for k = 2:50
        
  
    d(k) = 1 + (1/k);
   
   
    e(k) = abs( 1 - d(k) );
    
    if( e(k) == e(k-1) )
        
    end
    
    fprintf( k, a(k),e(k),e(k)/e(k-1),e(k)./e(k-1).^2)
    
end

Subject: Nested Functions Help

From: Joseph

Date: 12 Oct, 2010 13:24:04

Message: 2 of 3

What is the question?

"Don " <don.jackson@coker.edu> wrote in message <i9172n$1aq$1@fred.mathworks.com>...
> Say for instance I have a function x which when I call I want to display all the other functions I have written within the .m file
>
>
> function x = SequenceConverge(e,f,g,h)
>
>
> e = function a
>
> f = function b
>
> g = function c
>
> h = function d
>
> end
>
> function d()
> for k = 2:50
>
>
> d(k) = 1 + (1/k);
>
>
> e(k) = abs( 1 - d(k) );
>
> if( e(k) == e(k-1) )
>
> end
>
> fprintf( k, a(k),e(k),e(k)/e(k-1),e(k)./e(k-1).^2)
>
> end

Subject: Nested Functions Help

From: Image Analyst

Date: 12 Oct, 2010 13:38:03

Message: 3 of 3

Don:
You need to read the help on this, because this is really about the most fundamental, basic part of programming. In short, you don't need to put the word function to call it, so you just have
h = d();

Then your function definition for d() needs to have an output argument that you can send to h in your calling routine:
function output = d()
   output = 42; % Whatever you want to return.
   return; % Can also use end instead of return, or just have nothing.

In your case I think you might want to return e:
function e = d()
Then in your main program, e will get stuffed into h.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us