MATLAB: Transposing a 1×100 double to be a 100×1 double inside a Structure

double arraysreshapestructure arraystranspose

Hello,
I'm working with a large dataset, where everything is contained inside a structure array. Is there an easy way to transpose a double from 1×100 to 100×1 inside said array? Out of frustration I started doing it by hand, opening up a variable, right clicking and then hitting transpose, but there are 1576 columns that I need to do it for so I was hoping there would be an easier way to go about this.

Best Answer

By hand? At the very least do it in a loop! :)
Here's a simple method that you could do in 1 line of code. I wrote it in 2 lines for readability. Method: transpose data, store it in cell array, reassign it to structure/field. Note that this example uses transpose rather than the complex conjugate transpose .
% Fake data
s(1).f = rand(1,100);
s(2).f = rand(1,100);
s(3).f = rand(1,100);
c = arrayfun(@(x)x.f.', s, 'UniformOutput', 0);
s = cell2struct(c, 'f');
Related Question