Skip to content

Instantly share code, notes, and snippets.

View ahartlba's full-sized avatar

Andreas Hartl-Bachinger ahartlba

  • Austria
View GitHub Profile
@ahartlba
ahartlba / startup.m
Created December 19, 2023 06:16
Template for matlab startup Script
function [] = startup()
% Set up Plots
get(groot,'Factory');
set(groot,'DefaultLineLineWidth', 1.2);
set(groot,'defaultfigurecolor',[1 1 1]);
set(groot,'defaultAxesFontSize',11);
set(groot,'defaulttextinterpreter','latex');
set(groot,'defaultLegendInterpreter','latex');
set(groot,'defaultAxesTickLabelInterpreter','latex');
@ahartlba
ahartlba / unpacks.m
Created March 10, 2024 13:47
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);
@ahartlba
ahartlba / packs.m
Created March 10, 2024 13:48
Pack variables from current workspace into struct
function s = packs(varargin)
% pack struct
% if no arguments are passed in ... whole workspace gets packed
% else only arguments get parsed.
%
% Example:
%
% a = 4;
% b = 3;
% c = 15;
@ahartlba
ahartlba / unpack.m
Last active March 13, 2024 07:01
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