How to add rows to a blank table, created by an excel import which only contains headers
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ali
el 15 de Feb. de 2024
Respondida: Mathieu NOE
el 15 de Feb. de 2024
I've created an excel sheet with contains 1 row of just headers.
when using the
readtable("scriptTable.xlsx")
it created an empty table of size 0x7 (7 being the number of columns with headers)
however when i populate a row in excel and import it, i do indeed get a 1x7 table with the headers correctly set but the aim of this script is to populate this table programmatically.
I cannot get any of the add row functions commonly suggest online to add a row to the table of size 0x7.
is there a correct way to add a row in this case? or can I import it in a specifc way (I do not want to force a 'blank' row from within excel.
if isfile("scriptTable.xlsx")
T = readtable("scriptTable.xlsx","Sheet", "Artifacts",'PreserveVariableNames', true);
welcomePrompt;
else
disp("File does not exist")
end
(the excel sheet is nothing complex, just a single row of 7 headers, firstname, surname, dob etc)
1 comentario
VBBV
el 15 de Feb. de 2024
Do you want to add data rows to the excel file or to the existing table ?
Respuesta aceptada
Mathieu NOE
el 15 de Feb. de 2024
hello
why not this ? I simply used readcell to get the variable names from the excel file then populated the table (tehn you could save it to another excel file
TXT = readcell('DEMO1.xlsx'); % get the variable names (header line)
sz = [4 size(TXT,2)];
data = rand(sz); % populate with data
%create the table
T = array2table(data,'VariableNames',TXT)
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets 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!