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: arLink.m
    path of file: ./repos/d2d/arFramework3/Subfunctions
    
    the code of the file until where you have to start completion: % function arLink([silent], [tExpAdd], [dataAdd], [ix], [id], [im], [newData], [yStd], [add_sec])
%
% Link models, inputs and data sets. Has to be called whenever the
% linkage of experimental data to model, events or desired output time points 
% are changed.
%
%   silent      Do not show linking output.
%   tExpAdd     Manually add experimental time point (used by arPPL).
%   dataAdd     Data point to add (used by arPPL).
%   ix          Model state data point pertains to (used by arPPL).
%   id          Data index (used by arPPL).
%   im          Model index (used by arPPL).
%   newData     Data point to add (used by arPPL).
%   yStd        Standard deviation of new data point (used by arPPL).
%   add_sec     Are we adding a seco
    
function populate_threads( thread_fieldname, condition_fieldname, ntask_fieldname)

global ar;

% populate threads
ar.config.(thread_fieldname) = [];
ar.config.(thread_fieldname)(1).id = 0;
ar.config.(thread_fieldname)(1).n = 0;
ar.config.(thread_fieldname)(1).nd = 0;
ar.config.(thread_fieldname)(1).ms = int32([]);
ar.config.(thread_fieldname)(1).cs = int32([]);
ithread = 1;
ar.config.(ntask_fieldname) = 0;
for m = 1:length(ar.model)
    if (isfield(ar.model(m), condition_fieldname))
        for c = 1:length(ar.model(m).(condition_fieldname) )
            if(length(ar.config.(thread_fieldname))<ithread)
                ar.config.(thread_fieldname)(ithread).id = ithread-1;
                ar.config.(thread_fieldname)(ithread).n = 0;
                ar.config.(thread_fieldname)(ithread).nd = 0;
                ar.config.(thread_fieldname)(ithread).ms = int32([]);
                ar.config.(thread_fieldname)(ithread).cs = int32([]);
            end