modified the code so that the function accepts the data from refined code books matfiles