automating many column headings in table
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Kitt
el 30 de En. de 2025
Comentada: Kitt
el 30 de En. de 2025
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 comentarios
Respuesta aceptada
Star Strider
el 30 de En. de 2025
Perhaps something like this —
A = randn(5,10);
T1 = array2table(A, VariableNames=compose('physical state at step %4d',1:size(A,2)))
.
2 comentarios
Walter Roberson
el 30 de En. de 2025
Editada: Walter Roberson
el 30 de En. de 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)))
Más respuestas (0)
Ver también
Categorías
Más información sobre Data Preprocessing en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!