automating many column headings in table
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a 10000x400 matrix, plotphys, I want to turn into a table and add variable names to. I understand that can be done easily with the array2table function. However adding 400 headings is a lot; luckily I want the headings uniform in that they would be labeled
'phys state at tstep 1', 'phys state at tstep 2', ..., 'phys state at tstep 400'
Is there a way I can basically automate the creation of the headings?
I tried this
head = join("phys state at tstep " + [1:1:400]);
phystable = array2table(plotphys, 'VariableNames', {head});
but that did not work
댓글 수: 2
채택된 답변
Star Strider
2025년 1월 30일
Perhaps something like this —
A = randn(5,10);
T1 = array2table(A, VariableNames=compose('physical state at step %4d',1:size(A,2)))
.
댓글 수: 2
Walter Roberson
2025년 1월 30일
편집: Walter Roberson
2025년 1월 30일
The above uses column names 'physical state at step' followed by a 4 digit number that is right-justified with proceeding spaces -- which is certainly a valid option.
However, if you would prefer to use numbers that have no leading or trailing spaces, then
A = randn(5,10);
T1 = array2table(A, VariableNames="physical state at step "+(1:size(A,2)))
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Preprocessing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!