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

조회 수: 10 (최근 30일)
Carlos Carrasco
Carlos Carrasco 2018년 8월 23일
편집: Adam Danz 2018년 8월 24일
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.

채택된 답변

Adam Danz
Adam Danz 2018년 8월 23일
편집: Adam Danz 2018년 8월 24일
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');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by