blue_arkedia
blue_arkedia

Reputation: 471

creating function using matlab

I wrote the following function

% e is n×1 and y is n×1 vectors
function z=e_rand(e,y)
         b_LS=regress(e,y)
         z=b_LS*5

I saved the function in MATLAB toolbox. But when I run the function I get the following error: input argument "e" is undefined

How can I create the function correctly?

Upvotes: 1

Views: 256

Answers (2)

JesseBikman
JesseBikman

Reputation: 632

If you want to leave your function as-is, and encapsulate your function within another function, then you need to give e and y values in a parent function.

Try this:

    function parent()
    clear all, close all
    n = randi(10, 1)
    e = rand(n, 1)
    y = rand(n, 1)
    z = e_rand(e, y)

        % e is [n×1] and y is [n×1] vectors
        function z = e_rand(e, y)
                 b_LS = regress(e, y)
                 z = b_LS * 5
        end
    end

Works cited: http://www.mathworks.com/help/matlab/matlab_prog/nested-functions.html

Upvotes: 0

user85109
user85109

Reputation:

You DON'T RUN a function. You use it in an expression. You call your function at the command line. But you don't use the run command on a function. Run is only for scripts, not functions.

At the command line, just type this:

z = e_rand(e,y);

Upvotes: 6

Related Questions