?? mmv2struct.m
字號:
function varargout=mmv2struct(varargin)
%MMV2STRUCT Pack/Unpack Variables to/from a Scalar Structure. (MM)
% MMV2STRUCT(X,Y,Z,...) returns a structure having fields X,Y,Z,...
% containing the corresponding data stored in X,Y,Z,...
% Inputs that are not variables are stored in fields named ansN
% where N is an integer identifying the Nth unnamed input.
if nargin==0
error('Input Arguments Required.')
elseif nargin==1 % Unpack
arg=varargin{1};
if ~isstruct(arg)|length(arg)~=1
error('Single Input Must be a Scalar Structure.')
end
names=fieldnames(arg);
if nargout==0 % assign in caller
for i=1:length(names)
assignin('caller',names{i},getfield(arg,names{i}))
end
else % dump into variables
for i=1:nargout
varargout{i}=getfield(arg,names{i});
end
end
else % Pack
num=1;
for i=1:nargin
name=inputname(i);
if isempty(name)
name=sprintf('ans%d',num);
num=num+1;
end
eval(['y.' name '=varargin{i};'])
end
varargout{1}=y;
end
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -