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

PSR J1748-2446ad

Hey baby,

what’s the world coming to these days? It’s all going to hell isn’t it?
what if we just got away from it all? like light years away
fuck all that noise, all the people hurting each other
with the sky figuratively falling and with the economy and the people and the election and the state of things

you’re the one thing that’s good in the world


I was thinking

let’s just get away from it all, like you’ve always wanted

you and me in a cottage on the sea side
you know? Let’s do something crazy and just run away
we don’t need anyone if we have each other.
Just you and me
I can see you’re with me to the end no matter what
so let’s elope,

let’s go some where crazy

I’ve got the perfect spot in mind:
let’s go to PSR J1748-2446ad
what if we did that? let’s just get away
I know this is a little out of the blue, a little crazy, I can see you’re a little worried, but it’ll be perfect

let me tell you about J1748-2446ad

it’s a little spot up north, in Sagittarius, by Terzan 5, it’s exactly the kind of place we’ve always imagined we’d grow old together in

there’ll be plenty of room for kids if we want to have some

it’s a fix me up for sure, the heating’s a little wacky, it’s probably like 6×105K there year-round
but I love the way a little sweat looks on your skin

the foundation needs some work, the whole place might collapse into a black hole
but you’re all the foundation I’ve ever needed

it’s a bit bright there; 1.29×1026watts of emitted X-Rays would either instantly vaporize us or instantly give us cancer and then instantly vaporize us
I’m not worried about that though, your smile is pretty damn radiant and I haven’t vaporized yet, have I?

but it’s a perfect place to watch the sun set, though we might get a little motion sick because J1748-2446ad rotates at about 44,000 miles per hour. But you already spin me right round baby (like a record).
anyways, that’s 61,862,299 more sunsets a day we can watch together with our toes in neutron sand

also probably the wifi won’t be that good, what with us moving at 0.25 the speed of light and the 2.3×1013 Gauss magnetic field that will erase all of our devices

and also instantly destroy them

and also instantly crush our bodies

but I think it’s nice to unplug from everything every once in a while

we’ve got to watchkit for the tide, or at least the tidal forces, because J1748-2446ad’s gravitational field,
it’s about 106,387,117,347 times stronger than the earth’s

but together we’d figure out how to make it work
and once we get there it’ll be our own little paradise
what if we did it? what if we just got up and dropped everything and left right now?
with only high-energy astrophysics to bother you and I
we can finally have a cottage on the sea side like you always wanted

it’ll be just you and me

and a sea

of ultra-densely packed neutrons radiating gravitational waves into the starry sky

a place where we can just be us

just you and me
and PSR J1748-2446ad

everything is so grim these days


let’s just do it, let’s just drop everything and go
I know its late at night, babe, but it’s 18,000 light years a way so we better get going
it’ll take 134,123,326 more anniversaries to get there if we sling shot by Jupiter

we can celebrate on the road



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:




IMG_2730.JPGMuch like worried parents will fuss over a child before sending them off into the world, I fidgeted over the details of this lil guy, attempting to delay the inevitable departure, filled with pride and worry at the rigors he’ll face out in the real world. Unlike most worried parents, I eventually said “fuck it,” and dropped this fucker off at the local Fedex, to be shipped cross country in a large cardboard box.


The details were particularly sweat-able on this build, as this was essentially the third iteration on the concept, starting with a beast of the beats that went to Keith, and then a semi-pro configuration that went nowhere. Here are the vague details of the build:



Obviously, the first detail to isolate is the Lego theme. Legos, by the way, are a fairly mediocre permanent construction material. Turns out the 10-micron precision makes them fairly expensive from a cost/volume stand point (a small enclosure requires a lot of legos). Had my little siblings help me build lego boxes to compare the looks. Turns out rainbow is a crowd favorite


Fast forward a few days, after much designing, some deliberation, and then cutting, I’ve got a wood box to match the lego box. I believe I designed for 4L internal volume for each NS3 driver, which, in retrospect, I feel was too much. However, once the wood is cut…alea acta est. I went for a seamless miter approach on this build, to avoid the ugly “end-grain” of the birch plywood. I wrapped the grain around the “depth” of the box, but the grain of the “face” does not flow into the edges. So far I haven’t figured out a solution to this that works out in our boring 3 dimensional Euclidean / Newtonian universe.


Here we can see the translucence of the 3d prints, pre assembly. Originally, I had not planned for there to be a VU lightstrip in this build, but then I realized that since I built all the electronics off of the wood box, fitting them into the lego box, which had 5/6 faces constrained already, would be extremely difficult. At this point, I also realized I miscalculated the amount of space wires take up. Medusa rears her ugly cable management head yet again.


Now you see what I mean.


Analog signal processor demonstrating that I am the particular type of person that loves neat things but does not love making things neat, and so I live in a constant torment of my own devising. I chose a scheme that allows for a bass shelf at lower volumes, but flattens the EQ towards higher volumes—it’s essentially a loudness compensation circuit, except that since I have no reference for the actual loudness of the output (due to lack of information about source gain, listener position). I call it the “party” compensation circuit, because while one might enjoy deep sonorous extension at lower listening levels, once your friends roll through, 14 beers deep each, you’re cranking that fucking volume knob. And while the NS3’s have a lot of allowable excursion before crashing, the garbage bass lines that litter the hip hop soundscape are essentially glorified sine waves that will fuck your shit up. The obvious and simple solution to this is a simple dynamic gain-tied or signal-adaptive high-pass for excursion limiting, or a multi-band compressor. I leave these endeavors as an exercise to the reader until I have the time to implement them on the next build.IMG_2409.JPG

Pre-wood finishing. After disliking the gumminess and amber tint of marine spar varnish, I chose to use tung oil to bring out the figure. Then I sealed the box+3d printed parts with epoxy (bar top) for strength/durability, and finally, for UV protection and hardness, I finished with a clear gloss polycrylic. Here’s what it looks like finished:



Boombox The First

IN the way that most things in life are, there was no moment where the stars aligned and a beam of silver brilliance illuminated me with inspiration; it was not a sudden cataclysm of grand events or even a single moment of clarity. It was more the lucky coincidence of a few small dust mites, just little things, which only in detailed retrospection, could one notice an amount of circumstantial  alignment, that lead to thiswhich, of course, is on par with the scale of endeavor.

I was confronting my post-graduation ennui, as the evaporation of two of the more fulfilling experiences in my life (leading the water polo team, and learning tons of shit with tons of new people) had left me both without purpose and without the satisfaction of achievement of purpose. This was compounded by the fact that I had a degree in Mechanical engineering, which is a certification that I have all the necessary tools to be achieving things, but no job, which rendered those tools somewhat useless. I also other aligned mites; I had a little bundle of cash from graduation, a garage full of random bits of electronics, a shit load of time, and a best friend who wanted portable bluetooth speakers.

So I told him, I could build those for cheaper. He said fuck yeah, and I went to Urban Ore, where a quite lucky mite of dust fell into place; I found a use pair of drivers which just so happened to be the AuraSound NS4-255-4D. If this set of esoteric numbers doesn’t cause heart flutters, the NS4 is one of the best small format full-range drivers in the world, and it’s also impossible to get, because AuraSound was shut down by the feds. Th NS4 some how managed to sneak a little performance past the Iron Law;  it’s loud and it’s got bass in a small box, and it’s cheap (well, used to be cheap; the last commercially-available pair was bought by me, 1.5 years ago for $50). And somehow I had found a pair of these fuckers for $4.

And so I built him a damn boombox, and it’s design was mediocre, and the electrical engineering was shoddy, and the panels were cut from slightly different bits of wood, and nothing was quite lined up right, and it took all summer to get the right parts, and I ran up against the deadline of his birthday so I had to build for 2 days straight, and then it was the day of, and I hadn’t eaten all day because I had to finish it, and I was supposed to be leaving to go his house for a BBQ, and I was late, and I was and had been focusing for the last 8 hours to an extent that makes me wonder about the exact nature of my mental health, and I had my doubts about the whole thing because in someway the little guy’s success was entangled a bit with my own soul, but then it was time to go to his house, and since it was too late to turn back, I turned it on, for the first time, on the porch looking out to the sun setting over the Golden Gate, fog and clouds glowing with orange warmth, with my parents drinking a beer and my little siblings watching, and when the power light flicked on, and the beast was awakened with a bit of thunder, and the peaceful calm of a idyllic Berkeley summer sunset was shattered, I grinned.

Here’s the guy from that exact moment:


And Then The Rest

The response was positive, so I built a few more. Though, the first few efforts up until recently were a bit sophomoric, here are a few of them:


Here we’ve got some unfinished pictures of an ultra mini build with a 2 way design using a very surprising 3-inch sub that kicked low-end ass. Built into a (small) cake box.


Here’s some beer for scale:WP_20150117_11_02_35_Pro

Here’s the second NS4 build, with some Brazilian cherry I found on the side of the street. Shipped this one to the east coast. Not the most finished product I’ve made but it worked ok.


Eventually I realized that the finish (wood pun intended) is as important as the start so I worked on getting a cleaner look and looking into wood varnishes.WP_20150604_21_01_22_Pro

And the most recent piece, the KrumpKanon for Keith “I’ve been lifting so it can be heavy” Savran, complete with Lego detailing, a 200W sub, missile launch switches, and a marine spar varnish. It’s quite heavy.



So after all that talk of efficiency v extension, I figured I’d actually build something. It worked out that I ended up building on both sides of the coin, as the “Extension” build ended up being pretty gigantic. But the review of both approaches is in and it turns out that in some regards efficiency is more pleasant; I used the Faital Pro 5FE100 in a ~8L enclosure tuned to about 45-50 hz with a 3 inch x 15 inch port which I 3D-printed.  It WOMPS. Sounds great, crisp, powerful. Really pushes the “effortless” bass feeling, until you get below resonance and the woofer starts whacking around. It becomes excursion limited quite fast on songs with a lot of low frequency content, and it sounds pretty alarming. This forces my hand in ASP to put in a high pass around 32Hz-20Hz, adding complexity and heartache. But all in all, not a bad design.

As for the extension, which also sounds good, a different set of issues comes into play. I went with the Tang Band W5-1138SMF ~14L tuned to around 40 hz with a PR, and for starters, the thing is fucking gigantic. Despite the apparent size, 40 hz in 14L is pretty damn good, and it definitely has a presence visually and sonically. It sounds large, powerful, and it’s exceedingly hard to push the woofer itself into distortion. However  pushing the low efficiency of that driver is it’s ridiculous excursion capability, which brings an unexpected issue into play: high excursion means a lot of acceleration. A lot of acceleration mechanically means all kinds of shit is moving around, including things coupled to the boombox through the surface it’s on; put the boombox on the counter and all of a sudden the beer bottles on the counter start wiggling around too. Additionally, in the electrical domain, a lot of acceleration means a lot of voltage, which means more batteries.

These factors push the design to seem a lot less effortless than the 5FE100, potentially because the 1138 design seems to promote higher THD. It’s not necessarily a fair comparison, because the ASP, amp, and battery management on the 5FE100 design happens to be a lot better (I built it second, learned from previous mistakes). Normalizing for those factors, though, the smaller size is pretty great as it turns out that there is usually very little content from 40 Hz and below, and because larger boxes tend to be less efficient in terms of materials.


This slideshow requires JavaScript.