Transposing a 1x100 double to be a 100x1 double inside a Structure
10 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Adam Danz
on 23 Aug 2018
Edited: Adam Danz
on 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');
More Answers (0)
See Also
Categories
Find more on Structures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!