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".
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
You might have to check the values of the parameters m and n before the loop. They might be less than 15.