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".

Answers


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.


Need Your Help

Why is %E2%80%8F being added to my Youtube embed code?

javascript php jquery iframe youtube

I have a bunch of videos on Youtube which I embed using the same code. All of the videos worked fine until I uploaded the last one. Every time I now execute the code, %E2%80%8F is appended to the...

how to use context inside a static method to start an activity?

android static android-context

i have a button when its clicked it will trigger doStartAlarm(View v) and this method will trigger a static method startAlarmNow, when i click the button it will start the alarm but then the applic...