automating many column headings in table
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Star Strider
am 30 Jan. 2025
Perhaps something like this —
A = randn(5,10);
T1 = array2table(A, VariableNames=compose('physical state at step %4d',1:size(A,2)))
.
2 Kommentare
Walter Roberson
am 30 Jan. 2025
Bearbeitet: Walter Roberson
am 30 Jan. 2025
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)))
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!