Created
March 10, 2024 13:47
-
-
Save ahartlba/4e11bc37b68e267231c817cad5177258 to your computer and use it in GitHub Desktop.
Unpack Matlab Struct Contents into current workspace
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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