struct2var.m
来自「全面系统地给出鲁棒设计的源程序及运算实例」· M 代码 · 共 31 行
M
31 行
function struct2var(s)
%STRUCT2VAR Convert structure array to workspace variables.
% STRUCT2VAR(S) converts the M-by-N structure S (with P fields)
% into P variables defined by fieldnames with dimensions M-by-N. P
% variables are placed in the calling workspace.
%
% Example:
% clear s, s.category = 'tree'; s.height = 37.4; s.name = 'birch';
% c = struct2cell(s); f = fieldnames(s);
%
% See also STRUCT2CELL, FIELDNAMES.
if nargin < 1
error('struct2var:invalidInput','No input structure found')
elseif nargin > 1
error('struct2var:invalidInput','Too many inputs')
elseif ~isstruct(s)
error('struct2var:invalidInput','Input must be a structure data type')
end
[r,c] = size(s);
names = fieldnames(s);
for i=1:length(names)
assignin('caller',names{i},s.(names{i}))
end
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?