subget.m

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

M
80
字号
function pstruct = subget(hnd,props)
% subget  - get a list of properties as a struct
%
% this function simplifies getting multiple properties from
% MATLAB's graphics handle objects.
%
% FORMAT:       propstruct = subget(handle, props)
%
% Input fields:
%
%       handle      Nx1 graphic handles
%       props       either a single string or a cell array or
%                   strings naming properties of the handles
%
% Output fields:
%
%       propstruct  Nx1 structure array with property contents
%
% See also get.

% Version:  v0.5c
% Build:    6120415
% Date:     Dec-04 2006, 3:15 PM CET
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% enough arguments ?
if nargin < 2
    error( ...
        'BVQXtools:TooFewArguments',...
        'Too few arguments. Try ''help %s''.',...
        mfilename ...
    );
end

if isempty(hnd) || ...
   ~all(ishandle(hnd))
    error( ...
        'BVQXtools:BadArgument',...
        'Invalid handle argument.' ...
    );
end

if ischar(props), props = {props(:)'}; end
if ~iscell(props)
    error( ...
        'BVQXtools:BadArgument',...
        'Invalid props argument.' ...
    );
end

hnd     = hnd(:);
nhnd    = size(hnd,1);
pstruct = cell2struct(cell(1,1,0),{},3);

for cc = 1:numel(props)
    try
        get(hnd(1),props{cc});
        pstruct.(props{cc}) = [];
    catch
        % nothing
    end
end

props = fieldnames(pstruct);
if isempty(props)
    error( ...
        'BVQXtools:NoValidProperty',...
        'No valid property names given.' ...
    );
end

props = props(:)';
pstruct(1) = [];

values = get(hnd,props);
for cc = 1:size(props,2)
    [pstruct(1:nhnd,1).(props{cc})] = deal(values{:,cc});
end

⌨️ 快捷键说明

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