How to write this line of code to create a Matlab table?

조회 수: 1 (최근 30일)
Leon
Leon 2020년 12월 5일
댓글: Leon 2020년 12월 5일
I have unknown number of column variables in cell array:
Var{1} = [ 1; 2; 3; 4; 7];
Var{2} = [33; 10; 46; 7; 2];
...
If I knew how many variables I have, I would be able to manually form my table by:
T1 = table(Var{1}, Var{2}, ...);
The problem is that I do not know how many variables each time my program will generate. In this case, how could I write the code to create the table?
I tried the below, but it does not work:
T1 = table(Var);
Many thanks.

채택된 답변

Walter Roberson
Walter Roberson 2020년 12월 5일
cell2table and probably provide VariableNames parameter
  댓글 수: 10
Walter Roberson
Walter Roberson 2020년 12월 5일
Oh wait:
TT = table(Var{:});
should do the trick.
Leon
Leon 2020년 12월 5일
Hooray!!!
Thank you so much. I really appreciate your weekend time to help me out. Enjoy the rest of your weekend.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by