Transposing a 1x100 double to be a 100x1 double inside a Structure
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Carlos Carrasco
il 23 Ago 2018
Modificato: Adam Danz
il 24 Ago 2018
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.
0 Commenti
Risposta accettata
Adam Danz
il 23 Ago 2018
Modificato: Adam Danz
il 24 Ago 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');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Structures in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!