Last active
March 13, 2024 07:01
-
-
Save ahartlba/808f77339f0e00339f1e101884b4cab5 to your computer and use it in GitHub Desktop.
Python like unpacking for matlab
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 varargout = unpack(in) | |
% python-like unpacking of arrays | |
% simulink compatability, delete if not using in simulink | |
condition = coder.ignoreConst(nargout <= length(in)); # simulink compatible version (should work in matlab as well) | |
% condition = nargout <= length(in); # matlab code | |
assert(condition, 'To many value to unpack!') | |
if length(in) > nargout | |
n = nargout; | |
else | |
n = length(in); | |
end | |
for i=1:n-1 | |
if iscell(in) | |
varargout{i} = in{i}; | |
else | |
varargout{i} = in(i); | |
end | |
end | |
i = n; | |
if iscell(in) | |
varargout{i} = in{i:end}; | |
else | |
varargout{i} = in(i:end); | |
end | |
end | |
if iscell(in) | |
varargout{i} = in{i:end}; | |
else | |
varargout{i} = in(i:end); | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment