function [formatted] = significanceStarsMatrix(vals, critVals, models)
% Format test statistics with significance stars based on critical values
% Inputs:
%   vals      : [nRows x nCols] matrix of test statistics
%   critVals  : [nRows x nCols x 3] matrix of critical values for [10%, 5%, 1%]
%   rowLabels : optional, 1 x nRows cell array
%   colLabels : optional, 1 x nCols cell array
% Outputs:
%   formatted : cell array of formatted strings (e.g., "2.13**")
%   latexTable: string with LaTeX table code

    [nRows, nCols] = size(vals); 
    formatted = cell(nRows, nCols);
    stars = {'*', '**', '***'};

    for i = 1:nRows
        for j = 1:nCols
            val = vals(i,j);
            absVal = abs(val);
            % Use critical values from critVals(i,j,k)
            if absVal >= critVals(i,j,3)
                star = stars{3};
            elseif absVal >= critVals(i,j,2)
                star = stars{2};
            elseif absVal >= critVals(i,j,1)
                star = stars{1};
            else
                star = '';
            end
             % Bold if significant at 5%
             star = '';
            formattedStr = sprintf('%.2f%s', val, star);
            if absVal >= critVals(i,j,2)
                formattedStr = ['\textbf{' formattedStr '}'];
            end
            formatted{i,j} = formattedStr;
            %formatted{i,j} = sprintf('%.2f%s', val, star);
        end
    end

    formatted = [cellstr(models)'  formatted];
    
    % Number of columns
    nCols = size(formatted,2);
    
    % Preallocate new cell array
    B = cell(size(formatted,1), nCols*2 -1);
    
    % Fill B: insert original entries in odd positions
    B(:,1:2:end) = formatted;
    
    % Insert '&' in even positions
    B(:,2:2:end-1) = {'&'};

    formatted = [B repmat({'\\'},length(models),1)];
   
end