A Function to Un-Nest Nested Structures in MATLAB

So I’m flying back from Shanghai right now, (youalreadyknow it’s business class) and I decided to business-expense-splurge for the in-flight wifi, which is about as fast as a snail in the process of peacefully passing away. This means the only scrap of entertainment I can garner from my laptop is writing code in MATLAB. Writing fuckaround code in a pretend programming language in a rickety IDE has a provided surprising source of succor; if you were here you’d know it too because you’d notice I have been sitting FOR HOURS WITHOUT MY SEATBELT ON because I was simply too enraptured by the alternating tides of hate and happiness that MATLAB so easily exerts on the user.

Basically, I’m working on a GUI that allows a user to programmatically  create test limits for test data, while also allowing the user to efficiently adjust the limits where our absurd test data manages to invalidate centuries of statistical knowledge. This requires allowing the user to load a specific test from within an absurdly packaged data file which comes from a test system written by someone who clearly much prefers obfuscating and hiding things over effective data collection WHICH in turn means deeply and variably nested structures. Like 400-megabyte-CSV, stuck-in-limbo-with-Leonardio-DiCaprio, booger-that-you-can-feel-but-after-several-embarrassing-red-lights-you-cannot-remove levels deep.

Therefore, after careful perusal of mathworks, I wrote the following code. It uses recursion to return an array of strings describing each and every branch of a struct, down to the twig. It is surely my greatest accomplishment thus far.

function allfields=fieldnamesr(struct);
% FIELDNAMESR recursively explores the depths of nested structs To find all
% possible branches
%      fuck yeah recursion
fields=fieldnames(struct); %are there any field names?
idx=1; %increment variable
for i=1:1:size(fields,1) %for all field names
    if isstruct(struct.(fields{i})) %see if that field name itself is a structure 
        temp=structRecurrr(struct.(fields{i})); %if also structure, then we must go deeper!
        for j=1:1:length(temp) %for all returned values 
        allfields{idx,1}=sprintf('%s.%s',fields{i},temp{j}); %return a string containing returned values
        idx=idx+1; %increment
        allfields{idx}=fields{i}; %if field name not struct, then we are at bottom level
        idx=idx+1; %increment



Classic bro-split. With some things mixed up/distributed.


The idea is to cut effectively. The metabolic shift when cutting can reduce caloric deprivation efficacy for people with naturally slow metabolisms, while the energy deficiency can hurt those looking to preserve lean mass, especially for people with fast metabolisms, and people coming off of bulks. The plan is made for my friend (Aquadman) who is looking mainly to have visible abs, so the preservation of lean mass is somewhat secondary, but the theory is compound lifts for energy output and physiological stimulus, with a rotating high-intensity finish in order to add some spice.

Personally, while cutting, compounds and higher weekly lift frequency helps preserve lean mass. It’s completely anecdotal, but I’d guess the consistent stimulus keeps a muscle group from being in ignored by the body, while the compound lifts helps maintain a more anabolic hormonal balance.



This plan was developed for Ironvlad the Giggly and the Philibuster, two fairly light individuals who are training up for Muay Thai. The idea behind this is a simplistic 3-day/week periodized program to gain lean mass to develop functional strength for Muay Thai using barbells and dumbbells only–it is assumed that other more specific training will be done in the scope of the Muay Thai classes. The two individuals it’s intended for need to move up a weight class, so the idea is to split between large compound lifts in a strength rep/set scheme to build power and explosiveness and large compounds with accessories in a  hypertrophic rep/set schemes to help build lean mass. The mesocycle structure throws in some extra MUSCLE CONFUSION by changing movements and modulating intensity and volume through out the cycle. The gradual ratcheting of volume/intensity through the cycle, besides being a mainstay of periodization, is intended to take advantage of the bulk.


Essentially, the 1RM are establish on Week 0, which sets the weights for the next few weeks. Then a 6 week periodized mesocycle follows, with each cycle ending by re-establishing a (hopefully) higher 1RM. Obviously, the %1RM numbers and rep/set structures are guidelines, as the math they are based on is fairly generalized, and one sees a lot of variation day-to-day and person-to-person in response to volume/weight/bulking etc. And besides, sometimes your friends are watching and the cute chick you were staring at is vaguely looking in your direction wondering which of the sweaty, grunting, gym nerds is making so many noises and the random song that came on right before your set drops super hard and you deadlift your current 5RM for an easy 12 and you walk away like a light-headed, red-faced, veiny and skinless gorilla, so never let a prescribed rep number tell you what to do.

The structure of the lifts is 2 main movements, meant to be done at the rep and set and %1RM determined by the week number. This is then followed by 2 accessory super sets, which don’t really need to follow the mesocycle, though the recommendation is 4 x 6-10. The 2 accessory lifts vary through the week, and there’s a decoder ring which includes 2 versions for each accessory superset; the idea is to alternate between the  x.1 and x.2 versions one week to the next.

There’s also a little calculation section on the right which recommends the weekly intake, and daily recommended intake as per Ironvlad The Giggly’s BMR, activity, desired gains, desired time etc. Everything that’s green text in a green box is for user input, in order to calculate necessary intake.

Click here to download: