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!