function do_ols(feat_file,out_file,param_file,label_file,D)
    
    training = true;
    
    if(nargin < 3)
        fprintf('Not enough input parameters!\n');
        exit(1);
    elseif(nargin == 3)
        training = false;
        D = 100;
    end
    
    load(feat_file)
    
    if training
        load(label_file)
        
        nbeats = 0;
        nfeat = size(scattered{1},2);
        for i = 1:length(scattered)
            nbeats = nbeats + size(scattered{i},1);
        end
        
        X = zeros(nfeat,nbeats);
        Y = zeros(nbeats,1);
        
        beatind = 1;
        for i = 1:length(scattered)
            cnbeat = size(scattered{i},1);
            X(:,beatind:(beatind+cnbeat-1)) = scattered{i}';
            Y(beatind:(beatind+cnbeat-1)) = label_list(i);
            beatind = beatind + cnbeat;
        end
        
        redidx = pls_multiclass_v2(X,Y,unique(Y),D);
        
        save(param_file,'redidx')
              
    else
        load(param_file)
    end
    
    features = cell(1,length(scattered));
    for i = 1:length(scattered)
        if training
            cfmtx = scattered{i};
            features{i} = cfmtx(:,logical(redidx));
        else
            features = {squeeze(scattered(:,:,logical(redidx)))};
        end
    end

    clear scattered

    save(out_file,'features')  
    
end