user3250947
user3250947

Reputation: 1

matlab output from function

I am doing some matlab work and I am stuck on this function and can't find what's wrong.

That is my function

function [e] = Ek(fk,m,n)
for i=8:m-7
    for j=8:n-7 
        e(i,j)=some code here;
end 
end  

I am calling that function from an other file with this command

bla= Ek(array, m, n);

The error I am getting is

Error in Ek (line 2) for i=8:m-7

Output argument "e" (and maybe others) not assigned during call to "some path/Ek.m>Ek".

Upvotes: 0

Views: 99

Answers (2)

Matt J
Matt J

Reputation: 1137

You should be pre-allocating e, for example

function [e] = Ek(fk,m,n)

e=zeros(m,n);   %pre-allocate

for i=8:m-7
    for j=8:n-7 
        e(i,j)=some code here;
end 
end 

Upvotes: 1

Dinesh
Dinesh

Reputation: 2204

You might have to check the values of the parameters m and n before the loop. They might be less than 15.

Upvotes: 0

Related Questions