luis.quesada
luis.quesada

Reputation: 13

Error: `Input argument "N" is undefined`, in simple matlab program

I have this tiny program in Matlab.

laMatriz.m

function k = laMatriz(X)
    Y = 9;
    A = zeros(X, Y);    
    for i=1:X
        V = elVector(Y);
        LimY = length(elVector);
        for j=1:LimY
            A(i,j) = V(j); 
        end
    end
    k = A;
end


elVector.m

function elVector = elVector(N)
    %fprintf('largo de elVector %i\n', N);
    elVector=1:N;
end

Calling function laMatriz(10) results in this error:

??? Input argument "N" is undefined.

Error in ==> elVector at 3
    elVector=1:N;

Error in ==> laMatriz at 11
        LimY = length(elVector);

why? how can i fix it?

Upvotes: 1

Views: 2709

Answers (1)

Danny
Danny

Reputation: 2281

The problem is in this function:

function k = laMatriz(X)
    Y = 9;
    A = zeros(X, Y);    
    for i=1:X
        V = elVector(Y);
        LimY = length(elVector); <-- here you are calling length(elVector)
        for j=1:LimY
            A(i,j) = V(j); 
        end
    end
    k = A;
end

elVector is a function so you cannot call length with it. Did you mean length(V)? Basically your error is saying the argument N to the function elVector doesn't exist.

Upvotes: 1

Related Questions