How to transpose every cell in a table?
조회 수: 20 (최근 30일)
이전 댓글 표시
I have a table that contain array of double in every cell. It looks like this:
Column1 Column2
____________ ________________
1×7 double 1×27 double
1×7 double 1×27 double
1×7 double 1×27 double
1×7 double 1×27 double
1×7 double 1×27 double
But I need every cell to be 7x1 or 27x1, respectively (data in column vector, not row vector). How can I transpose it?
댓글 수: 1
the cyclist
2023년 3월 18일
Are your data truly in a table data object? Or possibly in a cell array (which is arguably the more common method for storing data like this)?
채택된 답변
the cyclist
2023년 3월 18일
편집: the cyclist
2023년 3월 18일
% If data are in a cell array
c = {rand(1,7),rand(1,27)}
ctrans = cellfun(@transpose,c,'UniformOutput',false)
% If data are in a table, convert to cell array, transpose, and convert back
t = table(rand(1,7), rand(1,27), 'VariableNames', {'t1','t2'})
ct = table2cell(t);
cttrans = cellfun(@transpose,ct,'UniformOutput',false);
ttrans = cell2table(cttrans)
There might be a more direct way to do this operation on a table, but I didn't think of one. Also, you'll need to rename the table variables.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!