필터 지우기
필터 지우기

Creating a table using cell arrays

조회 수: 5 (최근 30일)
Johnny Dessoulavy
Johnny Dessoulavy 2022년 1월 25일
댓글: Walter Roberson 2022년 1월 26일
Hi,
I am trying to create a table that has all of my varibale names on the left and then a series of results produced by different simulations be produced in sebsequent columns on the right.
I have only been able to get a single set of data to appear on a table, otherwise they appear as seperate tables. Any help would be appreciated.
Groups is an 11x1 string of the variable names
Results is a 2x1 cell array where each element is an 11x1 vector containing the results.
Table = table(Results,'RowNames',(Groups));

채택된 답변

Walter Roberson
Walter Roberson 2022년 1월 26일
Results = {randi(9, 11, 1); "R"+randi(9,11,1)}
Results = 2×1 cell array
{11×1 double} {11×1 string}
Groups = cellstr(('a':'k').')
Groups = 11×1 cell array
{'a'} {'b'} {'c'} {'d'} {'e'} {'f'} {'g'} {'h'} {'i'} {'j'} {'k'}
Table = table(Results{:}, 'RowNames', Groups)
Table = 11×2 table
Var1 Var2 ____ ____ a 5 "R1" b 4 "R2" c 8 "R9" d 6 "R3" e 5 "R4" f 9 "R2" g 9 "R6" h 5 "R3" i 2 "R1" j 1 "R4" k 3 "R1"
  댓글 수: 2
Johnny Dessoulavy
Johnny Dessoulavy 2022년 1월 26일
Thank you! worked perfectly. Would you know how to change the "var1" to something else?
Walter Roberson
Walter Roberson 2022년 1월 26일
Use the 'VariableNames' option

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by