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: arSaveData.m
    path of file: ./repos/d2d/arFramework3/Advanced
    
    the code of the file until where you have to start completion: % arSaveData(m, jplot)
%
% Save data sets corresponding to the plot with index jplot to csv file
% into the subfolder /Data
%
%   m      [1:length(ar.model)]           position of model			
%   jplot  [1:length(ar.model(m).plot)]   position of plot
%
% The data file is saved to ['./Data/' ar.model(m).plot(jplot).name '.csv']

function arSaveData(m, jplot)

global ar

if(isempty(ar))
	error('please initialize by arInit')
end

if(~exist('Data', 'dir'))
	mkdir('Data')
end

if(~exist('m','var'))
    for jm=1:length(ar.model)
        for jplot=1:length(ar.model(jm).plot)
            arSaveData(jm, jplot)
        end
    end
    return
end
if(~exist('jplot','var'))
    for jplot = 1:length(ar.model(m).plot)
        arSa
    
function arSaveData(m, jplot)

global ar

if(isempty(ar))
	error('please initialize by arInit')
end

if(~exist('Data', 'dir'))
	mkdir('Data')
end

if(~exist('m','var'))
    for jm=1:length(ar.model)
        for jplot=1:length(ar.model(jm).plot)
            arSaveData(jm, jplot)
        end
    end
    return
end
if(~exist('jplot','var'))
    for jplot = 1:length(ar.model(m).plot)
        arSaveData(m, jplot)
    end
    return
end
if(~isfield(ar.config,'useFitErrorMatrix'))
    ar.config.useFitErrorMatrix = false;
end

fname = ['./Data/' ar.model(m).plot(jplot).name '.csv'];
fprintf('saving data from model #%i, plot #%i, %s...', m, jplot, fname);

fid = fopen(fname, 'w');

jd = ar.model(m).plot(jplot).dLink(1);

% save to file
fprintf(fid, '"%s",', ar.model(m).data(jd).tUnits{3});

% conditions
if(~isempty(ar.model(m).data(jd).condition))
    for jp = 1:length(ar.model(m).data(jd).condition)
        fprintf(fid, '"%s",', ar.model(m).data(jd).condition(jp).parameter);
    end