Transposing a 1x100 double to be a 100x1 double inside a Structure

10 Ansichten (letzte 30 Tage)
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 1x100 to 100x1 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.

Akzeptierte Antwort

Adam Danz
Adam Danz am 23 Aug. 2018
Bearbeitet: Adam Danz am 24 Aug. 2018
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');

Weitere Antworten (0)

Kategorien

Mehr zu Structures finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by