Save variables (vector) to a tabulated text file
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Bill White
el 13 de Sept. de 2024
Comentada: Ive J
el 13 de Sept. de 2024
I have several vectors of data in my workspace, say A,B,C,D.....
Is it possible to save / export these vectors in a single tabulated text file that can be opened in a spreadsheet (such as excel) in columns?
I would like the colums to have headers, with the name of the vector (A, B, C, D etc.), and if possible, the file to have a name that I can choose.
regards
W
0 comentarios
Respuesta aceptada
Ive J
el 13 de Sept. de 2024
A = randn(10, 1); B = randn(10, 1);
tab = array2table([A, B], VariableNames=["A", "B"]); % as a table
writetable(tab, "mytab.xlsx") % write to an Excel file
2 comentarios
Steven Lord
el 13 de Sept. de 2024
You're assuming that A and B have types that are compatible for concatenation. Instead I'd simply call table rather than concatenating and calling array2table. That doesn't assume or require that the types be concatenatable.
A = randn(5, 1);
B = randn(5, 1);
dt = datetime(2024, 9, randi(30, 5, 1));
tab1 = table(A, B, dt)
tab2 = array2table([A, B, dt], VariableNames = ["A", "B", "dt"]) % won't work
Más respuestas (0)
Ver también
Categorías
Más información sobre Tables 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!