How to add rows to a blank table, created by an excel import which only contains headers

1 vue (au cours des 30 derniers jours)
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)

Réponse acceptée

Mathieu NOE
Mathieu NOE le 15 Fév 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)
T = 4×5 table
Sanchez Johnson Li Diaz Brown _______ _______ ________ ________ _______ 0.49551 0.83019 0.29608 0.040213 0.97074 0.9794 0.58094 0.39189 0.65952 0.69759 0.87414 0.0822 0.70589 0.42361 0.28346 0.44907 0.52833 0.085856 0.14904 0.56365

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by