Skip to content

Instantly share code, notes, and snippets.

@ahartlba
Created March 10, 2024 13:47
Show Gist options
  • Save ahartlba/4e11bc37b68e267231c817cad5177258 to your computer and use it in GitHub Desktop.
Save ahartlba/4e11bc37b68e267231c817cad5177258 to your computer and use it in GitHub Desktop.
Unpack Matlab Struct Contents into current workspace
function [] = unpacks(s)
% unpack struct
% unpacks 1 dimension into workspace that calls this function
assert(isstruct(s) && length(s) == 1, 'Only supply a struct!');
fieldnames = fields(s);
for i=1:length(fieldnames)
name = fieldnames{i};
value = s.(name);
assignin("caller", name, value);
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment