필터 지우기
필터 지우기

Efficient way to convert m by n array into a single column table with each row containing n by 1 array?

조회 수: 7 (최근 30일)
Let's say I have a 4 by 3 array:
A = [1 3 5; 2 6 7; 5 8 9; 3 2 1];
What is the fastest/most memory efficient way of converting this into a single column table with the first row containing a column array of the first row of A, the second row containing a column array of second row of A etc.
I would like to end up with something like the result of the following:
row1 = A(1, :)';
row2 = A(2, :)';
row3 = A(3, :)';
row4 = A(4, :)';
A = table({row1; row2; row3; row4})
A = 4×1 table
Var1 ____________ {3×1 double} {3×1 double} {3×1 double} {3×1 double}
What is the best way to automate this for an arbitrary m by n array - preferably without using a loop.

채택된 답변

Stephen23
Stephen23 2023년 4월 19일
A = [1 3 5; 2 6 7; 5 8 9; 3 2 1];
T = cell2table(num2cell(A.',1).')
T = 4×1 table
Var1 ____________ {3×1 double} {3×1 double} {3×1 double} {3×1 double}

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by