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: calc_group.m
    path of file: ./repos/CanlabCore/CanlabCore/External/spider/functions
    
    the code of the file until where you have to start completion: 
function [r]= calc_group(d,param)
  
% r=GROUP(data,param)
%
% Group data objects into cell arrays : the idea is that one groups
% data objects into a cell array of cell arrays, so that each cell
% array is a group with several members. Then various functions can be
% applied to this grouping e.g the wilcoxon test or calculating the mean
% error of each group.
%
% Data can be grouped in the follow ways (according to the value of param):
    
function [r]= calc_group(d,param)
  
% r=GROUP(data,param)
%
% Group data objects into cell arrays : the idea is that one groups
% data objects into a cell array of cell arrays, so that each cell
% array is a group with several members. Then various functions can be
% applied to this grouping e.g the wilcoxon test or calculating the mean
% error of each group.
%
% Data can be grouped in the follow ways (according to the value of param):
% 'cv'     : groups according to algorithms using cv folds 
% 'rotate' : rotates cell array so groups become members and members are groups
% 'flat'   : flatten cell array of cell arrays into single array
% only groups objects according to algorithms used in cv

%% defaults
if nargin==1
 if length(d{1})==1  %% flat structure -- assume cv
  k=findstr(d{1}.name,'fold='); 
  if ~isempty(k)   
    param='cv';
    disp('[group: assuming cv folds]');
  else
    param='flat';
    disp('[group: assume single set]');
  end