% STRUCTCAT takes a structure y of arbitrary dimensionality Mx. It's very straightforward to embed this into a simple function (also available on GitHub):įunction x = structcat(y, param) The above works because Matlab stores data in column-major order. However, it's easy to just get those back by one final reshape:Ĭatdat = reshape(catdat, ) The operation of concatenating vectors or matrices under MATLAB is defined as a combination of the variables in a single vector or matrix. Which unfortunately flattens all those 36x7x2 dimensions such that To get out the data into one big 6-dimensional array, I first concatenated along the fourth dimension:Ĭatdat = cat(4, angerspctrm) The structures were all tucked into one structure variable allconns such that I was dealing with Granger causality spectra that are stored in FieldTrip structures as follows:Īnd I had one of these structures per participant, per condition of my experiment, and per time-direction (forward or reverse details don't really matter here). Let me motivate the problem with an example.
In fact, it has happened so often that I decided to write a (very simple) general solution to this problem. Don't you just hate when you have an MxN struct array in Matlab, where each element contains some PxK data field, and you just really want to have all that data in a single PxKxMxN array? OK, maybe this doesn't happen to you very frequently, but it has happened to me.