from
Map fields of a structure to output variables
by Hoi Wong
The program assigns each field of a structure into output arguments.
|
| varargout=struct2vars(S)
|
function varargout=struct2vars(S)
% This is made in response to one of the comments in:
% http://blogs.mathworks.com/loren/2008/01/24/deal-or-no-deal/
%
% The program assigns each field of a structure into output arguments.
%
% s =
% a: 1
% b: [1 2 4]
% c: [5x2 double]
% d: 'test'
% e: {[3]}
%
% >> [a b c d e]=struct2vars(s)
%
% a =
% 1
%
% b =
% 1 2 4
%
% c =
% 0.8147 0.0975
% 0.9058 0.2785
% 0.1270 0.5469
% 0.9134 0.9575
% 0.6324 0.9649
%
% d =
% test
%
% e =
% [3]
%
% Even better if you're trying to dump a struct into the workspace:
%
% T=fieldnames(S);
% [T{:}]=struct2vars(S);
%
%
% By Hoi Wong (Mar/10/2009)
C = struct2cell(S);
varargout = {C{:}};
|
|
Contact us at files@mathworks.com