You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: WriteTopics.m
    path of file: ./repos/CBIG/external_packages/matlab/non_default_packages/topictoolbox
    
    the code of the file until where you have to start completion: function [ S ] = WriteTopics( WP , BETA , WO , K , E , M , FILENAME )
%% Function WriteTopics
%%

    
function [ S ] = WriteTopics( WP , BETA , WO , K , E , M , FILENAME )
%% Function WriteTopics
%%
% |[ S ] = WriteTopics( WP , BETA , WO )| writes the most likely entities
% (e.g. words, authors) per topic to a cell array of strings. |WP| is a
% sparse |W| x |T| count matrix such that |WP(i,j)| contains the number of times
% entity |i| has been assigned to topic |j| (|W|=number of entities, |T|=number of
% topics). |BETA| is the relevant hyperparameter used in the Gibbs sampling
% routine. |WO| is a cell structure of strings such that |WO{i}| contains the ith 
% entity string (e.g., word or author name)
%
% |[ S ] = WriteTopics( WP , BETA , WO , K , E , M , FILENAME )|
% writes the |K| most likely entities per topic to a text file |FILENAME|  
% with |M| columns. |E| is a threshold on the topic listings in |S|. Only
% entities that do not exceed this cumulative probability are listed.
% 
%%
% |WriteTopics( WP , BETA , WO , K , E , M , FILENAME )| writes the |K| 
% most likely entities per topic without producing a cell array of strings
% 
%
%%
% |[ S ] = WriteTopics( WP , BETA , WO  )| uses default values |K=5| and
% |E=1|
% 
%%
% Example
%
%%
%     |load 'ldasingle_psychreview'|
%     |[ S ] = WriteTopics( WP , BETA , WO )|
%
%%
% will list the most likely words per topic in the saved |WP| sample 
%
%%
%     |WriteTopics( WP , BETA , WO , 10 , 1.0 , 4 ,
%     'topics50_psychreview.txt' )|
%%
% will write 10 most likely words per topic to a four column text file

if (nargin>7)
    error( 'Too many input arguments' );
elseif (nargin<3)
    error( 'Too few input arguments' );
end