bvqx_srf_writeneighbors.m

来自「toolbox of BVQX, This is the access betw」· M 代码 · 共 83 行

M
83
字号
function bvqx_srf_writeneighbors(fid, varargin)
% bvqx_srf_writeneighbors  - write neighbors to SRF file
%
% FORMAT:       bvqx_srf_parseneighbors(fid, neighbors [, sanitycheck])
%
% Input fields:
%
%       fid         input file fid (fopen)
%       neighbors   Nx2 cell array with neighbor numbers and lists
%       sanitychecks, if given, check number of neighbors and content
%
% See also BVQXfile, bffio, bvqx_srf_parseneighbors

% Version:  v0.7b
% Build:    7083015
% Date:     Aug-30 2007, 3:23 PM CEST
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% argument check
if nargin < 2 || ...
   ~isa(fid, 'double') || ...
    isempty(fid) || ...
   ~isreal(fid) || ...
   ~any(fopen('all') == fid(1)) || ...
   ~iscell(varargin{1}) || ...
    isempty(varargin{1}) || ...
    length(size(varargin{1})) ~= 2 || ...
    size(varargin{1}, 2) ~= 2
    error( ...
        'BVQXtools:BadArgument', ...
        'Bad or missing argument.' ...
    );
end
neighbors = varargin{1};

% grand TRY loop
try
    
% without checks
if nargin < 3

    % loop over content
    for nc = 1:size(neighbors, 1)

        % write number of neighbors
        fwrite(fid, numel(neighbors{nc, 2}), 'uint32');

        % write neighbors 
        fwrite(fid, neighbors{nc, 2}(:) - 1, 'uint32');

    end

% with checks
else

    % loop over content
    for nc = 1:size(neighbors, 1)

        % check number of neighbors
        if isemtpy(neighbors{nc, 1}) || ...
            neighbors{nc, 1}(1) ~= numel(neighbors{nc, 2})
            error('BAD_NEIGHBORS_LIST');
        end

        % write number of neighbors
        fwrite(fid, numel(neighbors{nc, 2}), 'uint32');

        % write neighbors 
        fwrite(fid, neighbors{nc, 2}(:), 'uint32');

    end
end

% error handling
catch
    error( ...
        'BVQXtools:BadFileOrContent', ...
        'Writing of file failed with: ''%s''.', ...
        lasterr ...
    );
end

⌨️ 快捷键说明

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