Skip to content

Instantly share code, notes, and snippets.

@ahartlba
Last active March 13, 2024 07:01
Show Gist options
  • Save ahartlba/808f77339f0e00339f1e101884b4cab5 to your computer and use it in GitHub Desktop.
Save ahartlba/808f77339f0e00339f1e101884b4cab5 to your computer and use it in GitHub Desktop.
Python like unpacking for matlab
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