⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vmp_update.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
📖 第 1 页 / 共 2 页
字号:
        % check version
        if isempty(reqv) || ...
           ~isa(reqv, 'double') || ...
            isnan(reqv(1)) || ...
            isinf(reqv(1)) || ...
            fix(reqv(1)) ~= reqv(1) || ...
            reqv(1) < 2 || ...
            reqv(1) > 5 || ...
            isempty(oldv) || ...
           ~isa(oldv, 'double') || ...
            isnan(oldv(1)) || ...
            isinf(oldv(1)) || ...
            fix(oldv(1)) ~= oldv(1) || ...
            oldv(1) < 2 || ...
            oldv(1) > 5

            % give warning if required
            warning( ...
                'BVQXfile:InvalidPropertyValue', ...
                'Invalid old/new FileVersion value.' ...
            );

            % guess better values
            reqv = 5;
            bc.FileVersion = reqv;
            if bc.NativeResolutionFile
                oldv = 5;
            else
                oldv = 4;
            end
        end
        
        % if resolution is 1 make sure to go to old format
        if bc.Resolution == 1
            reqv = 4;
        end

        % something to do?
        if (oldv < 5 && reqv < 5) || ...
           (oldv > 4 && reqv > 4)
            bvqxfile_setcont(hfile.L, bc);
            return;
        end
        
        % build new content
        newCONT = bvqxfile_vmp.defaults{reqv};
        oldMap  = bc.Map;
        newMap  = newCONT.Map;

        % upgrade
        if oldv < 5
            
            % set global values
            newCONT.NativeResolutionFile = 1;
            newCONT.NrOfMaps   = numel(oldMap);
            newCONT.XStart     = bc.XStart;
            newCONT.XEnd       = bc.XEnd;
            newCONT.YStart     = bc.YStart;
            newCONT.YEnd       = bc.YEnd;
            newCONT.ZStart     = bc.ZStart;
            newCONT.ZEnd       = bc.ZEnd;
            newCONT.Resolution = bc.Resolution;
            dimres = newCONT.Resolution;
            dimX = (newCONT.XEnd - newCONT.XStart) / dimres;
            dimY = (newCONT.YEnd - newCONT.YStart) / dimres;
            dimZ = (newCONT.ZEnd - newCONT.ZStart) / dimres;
            if any([dimX, dimY, dimZ] ~= fix([dimX, dimY, dimZ]))
                error( ...
                    'BVQXfile:DimensionError', ...
                    'X/Y/Z Start/End values must match with Resolution.' ...
                );
            end
            
            if newCONT.NrOfMaps > 0
                newres = newCONT.Resolution;
                oldres = [ ...
                    (newCONT.XEnd - newCONT.XStart) / size(oldMap(1).VMPData, 1), ...
                    (newCONT.YEnd - newCONT.YStart) / size(oldMap(1).VMPData, 2), ...
                    (newCONT.ZEnd - newCONT.ZStart) / size(oldMap(1).VMPData, 3)];
                if any(oldres ~= fix(oldres))
                    oldres = [ ...
                        (1 + newCONT.XEnd - newCONT.XStart) / size(oldMap(1).VMPData, 1), ...
                        (1 + newCONT.YEnd - newCONT.YStart) / size(oldMap(1).VMPData, 2), ...
                        (1 + newCONT.ZEnd - newCONT.ZStart) / size(oldMap(1).VMPData, 3)];
                end
                if any(diff(oldres)) || ...
                    any(oldres ~= fix(oldres))
                    error( ...
                        'BVQXfile:DimensionError', ...
                        'Map dimension mismatch with in X/Y/Z Start/End.' ...
                    );
                end
                oldres = oldres(1);
                difres = newres / oldres;
                if difres ~= fix(difres)
                    scrds = 1:difres:(difres * (max([dimX, dimY, dimZ]) + 1));
                end
            end
            
            % iterate over maps
            for mc = 1:numel(oldMap)
                
                % set values
                newMap(mc).Type               = oldMap(mc).Type;
                newMap(mc).LowerThreshold     = oldMap(mc).LowerThreshold;
                newMap(mc).UpperThreshold     = oldMap(mc).UpperThreshold;
                newMap(mc).Name               = oldMap(mc).Name;
                newMap(mc).RGBLowerThreshPos  = oldMap(mc).RGBLowerThreshPos;
                newMap(mc).RGBUpperThreshPos  = oldMap(mc).RGBUpperThreshPos;
                newMap(mc).RGBLowerThreshNeg  = oldMap(mc).RGBLowerThreshNeg;
                newMap(mc).RGBUpperThreshNeg  = oldMap(mc).RGBUpperThreshNeg;
                newMap(mc).UseRGBColor        = oldMap(mc).UseRGBColor;
                newMap(mc).TransColorFactor   = oldMap(mc).TransColorFactor;
                newMap(mc).NrOfLags           = oldMap(mc).NrOfLags;
                newMap(mc).MinLag             = oldMap(mc).MinLag;
                newMap(mc).MaxLag             = oldMap(mc).MaxLag;
                newMap(mc).CCOverlay          = oldMap(mc).CCOverlay;
                newMap(mc).ClusterSize        = ...
                    round(oldMap(mc).ClusterSize / difres ^ 3);
                newMap(mc).EnableClusterCheck = oldMap(mc).EnableClusterCheck;
                newMap(mc).UseValuesAboveThresh = ...
                    oldMap(mc).UseValuesAboveThresh;
                newMap(mc).DF1                = oldMap(mc).DF1;
                newMap(mc).DF2                = oldMap(mc).DF2;
                newMap(mc).ShowPositiveNegativeFlag = 3;
                newMap(mc).BonferroniValue    = oldMap(mc).BonferroniValue;
                newMap(mc).NrOfFDRThresholds  = numel(bvqxfile_vmp.fdr);
                newMap(mc).UnknownValue       = -1;
                newMap(mc).TimePointData      = zeros(0, 1);
                if difres == fix(difres)
                    newMap(mc).VMPData        = ...
                        oldMap(mc).VMPData(1:difres:end-1, 1:difres:end-1, 1:difres:end-1);
                else
                    newMap(mc).VMPData        = ...
                        interp3(oldMap(mc).VMPData, ...
                            scrds(1:dimX), scrds(1:dimY), scrds(1:dimZ));
                end
                
                % build FDR table
                try
                    mvals = newMap(mc).VMPData( ...
                        ~isnan(newMap(mc).VMPData(:)) & ...
                        (newMap(mc).VMPData(:) ~= 0));
                    if ~isempty(mvals)
                        switch (newMap(mc).Type)
                            case {1}  % t-score
                                newMap(mc).FDRThresholds = ...
                                    [bvqxfile_vmp.fdr(:), ...
                                    custom_tinv(1 - fdr_thresholds( ...
                                    1 - custom_tcdf(abs(double(mvals)), ...
                                    newMap(mc).DF1), ...
                                    bvqxfile_vmp.fdr(:) / 2, true), newMap(mc).DF1)];
                            case {4}  % F-score
                                newMap(mc).FDRThresholds = ...
                                    [bvqxfile_vmp.fdr(:), ...
                                    custom_finv(1 - fdr_thresholds( ...
                                    1 - custom_fcdf(abs(double(mvals)), ...
                                    newMap(mc).DF1, newMap(mc).DF2), ...
                                    bvqxfile_vmp.fdr(:), true), ...
                                    newMap(mc).DF1, newMap(mc).DF2)];
                            otherwise
                                error('FDR_ERROR');
                        end
                    else
                        newMap(mc).NrOfFDRThresholds = 1;
                        newMap(mc).FDRThresholds = [0, 1e5, 1e5];
                    end
                catch
                    newMap(mc).NrOfFDRThresholds = 1;
                    newMap(mc).FDRThresholds = [0, 1e5, 1e5];
                end
            end
            
            % put Map into new object
            newCONT.Map = newMap;
            
        % downgrade
        else
            
            newCONT.NativeResolutionFile = 1;
            newCONT.NrOfMaps   = numel(oldMap);
            newCONT.XStart     = bc.XStart;
            newCONT.XEnd       = bc.XEnd;
            newCONT.YStart     = bc.YStart;
            newCONT.YEnd       = bc.YEnd;
            newCONT.ZStart     = bc.ZStart;
            newCONT.ZEnd       = bc.ZEnd;
            newCONT.Resolution = 1;
        end
        
        % put back into object
        bc = newCONT;
end

% set back
bvqxfile_setcont(hfile.L, bc);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -