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

📄 subsasgn.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function hIniFile = subsasgn(hIniFile, S, V)
% BVQXinifile::subsasgn  - write settings to an ini-file
%
% FORMAT:       IniFileObject.STRUCT = inistruct;
%        or     IniFileObject.Section  = section;
%        or     IniFileObject.Section.Setting = value;
%
%    For multi-dimensional object arrays, the typical indexing is valid.
%    However, only singular objects may be used for write access.

% Version:      v0.7b
% Build:        7090311
% Date:         Sep-03 2007, 11:35 AM CEST
% Author:       Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL / Info:   http://wiki.brainvoyager.com/BVQXtools

% class check
if nargin > 2 && ...
    ~isa(hIniFile, 'BVQXinifile')
    try
        hIniFile = builtin('subsasgn', hIniFile, S, V);
    catch
        rethrow(lasterror);
    end
    return;
end

% argument check
if isempty(S)
    error( ...
        'BVQXinifile:BadSubsAsgn', ...
        'S struct may not be empty.' ...
    );
end
slen= length(S);
stype = S(1).type;
ssubs = S(1).subs;

% decide on kind of subscripting, first struct-like notation
switch stype, case {'.'}

    % check for subscript type
    if ~ischar(ssubs) || ...
        isempty(ssubs)
        error( ...
            'BVQXinifile:BadSubsAsgn', ...
            'Struct notation needs a non-empty char subscript.' ...
        );
    end

    % only works for singular object
    if numel(hIniFile) ~= 1 || ...
       ~hIniFile.L
        error( ...
            'BVQXinifile:InvalidFileID', ...
            'Struct notation only works for valid, singular objects.' ...
        );
    end

    % make content linear
    ssubs = ssubs(:)';

    % complete or section ?
    if slen == 1
        
        % only valid for struct values
        if ~isstruct(V)
            error( ...
                'BVQXinifile:BadSubsAsgnValue', ...
                'A struct value is needed for an only struct subscript.' ...
            );
        end
        
        % complete requested
        if strcmp(ssubs, 'STRUCT')
            try
                BVQXinifile(hIniFile, 'setinicomplete', V);
            catch
                rethrow(lasterror);
            end

        % section requested
        else
            try
                BVQXinifile(hIniFile, 'setinisection', S(1).subs, V);
            catch
                rethrow(lasterror);
            end
        end

    % setting or subsetting
    else

        % require second subscript to also be CHAR
        if ~strcmp(S(2).type, '.') || ...
           ~ischar(S(2).subs) || ...
            isempty(S(2).subs)
            error( ...
                'BVQXinifile:BadSubsAsgn', ...
                'At least two CHAR struct subscripts are needed.' ...
            );
        end

        % subsetting requested
        if length(S) > 2
            try
                % get setting
                rvalue = BVQXinifile( ...
                    hIniFile, 'getinisetting', S(1).subs, S(2).subs);
                
                % assign changes
                subsasgn(rvalue, S(3:end), V);
                
                % store changes setting
                BVQXinifile( ...
                    hIniFile, 'setinisetting', S(1).subs, S(2).subs, rvalue);
            catch
                error( ...
                    'BVQXinifile:IllegalSubsAsgn', ...
                    'Couldn''t pass subsasgn to %s.%s.', ...
                    S(1).subs, ...
                    S(2).subs ...
                );
            end
            
        % set value directly
        else
            try
                BVQXinifile( ...
                    hIniFile, 'setinisetting', S(1).subs, S(2).subs, V);
            catch
                rethrow(lasterror);
            end
        end
    end

% indexing requested
case {'()'}

    % we need non-empty cell subscript
    if ~iscell(ssubs) || ...
        isempty(ssubs)
        error( ...
            'BVQXinifile:BadSubsRef', ...
            'Can''t index into BVQXinifile matrix.' ...
        );
    end

    % convert hIniFile to struct
    sIniFile = struct(hIniFile);

    % try to retrieve subscripted matrix
    try
        subset = subsref(sIniFile, S(1));
    catch
        error( ...
            'BVQXinifile:BadSubsRef', ...
            'Invalid subscript (%s).', ...
            lasterr ...
        );
    end

    % no further subsasgn requested
    if slen == 1
        if ~isa(V, 'BVQXinifile')
            error( ...
                'BVQXinifile:BadSubsAsgnValue', ...
                'Class mismatch error.' ...
            );
        end
        
        % try to assign new objects into matrix
        try
            sIniFile = subsasgn(sIniFile, S(1), struct(V));
            hIniFile = class(sIniFile, 'BVQXinifile');
        catch
            error( ...
                'BVQXinifile:BadSubsAsgnIndex', ...
                'Couldn''t assign partial object matrix (%s).', ...
                lasterr ...
            );
        end
        return;
    end

    if numel(subset) ~= 1 || ...
       ~subset.L
        error( ...
            'BVQXinifile:InvalidFileID', ...
            'Further subscripting only works for valid, singular objects.' ...
        );
    end

    try
        subsasgn(class(subset, 'BVQXinifile'), S(2:end), V);
    catch
        rethrow(lasterror);
    end

otherwise
    error( ...
        'BVQXinifile:BadSubsAsgn', ...
        'Only struct notation allowed to set values.' ...
    );
end

⌨️ 快捷键说明

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