It is not advisable to use clc inside most functions. There is not typically a reason to clear the command window.
You should never "clear all" inside a function. If you use "clear all" at all, it should only be inside one script that you use to reset the state of MATLAB when you switch tasks. "clear all" inside a function is like Wyle E. Coyote blowing up the bridge he is standing on.
Setting a variable to  in every iteration of a loop is not productive in most cases. If the variable is not being set to something else inside the loop before being set to  then you are just wasting time.
Every iteration of for j you clear all of WK, making it into an array of size 0. Then in for i you try to access WK(1) on the first iteration, but offset (1) is not there because you wrote  to WK (multiple times)