xlswrite is not recommended, what should I use instead?
Afficher commentaires plus anciens
I have eleven 12x8 matrices composed of 1s and 0s. I want to export each matrix into its own excel file as a table with the rows labeled with times and the columns labeled with weekdays. I want to use an efficient code and possibly a loop to prevent typing over and over again. Each Matrix is saved as as a variable, like 'A53'. Of the eleven matrices, ten are have consecutive counting titles, like 'A51', 'A52', 'A53'...'A60'. Is it possible to use a loop to load these into separate excel sheets, as described above?
Réponses (1)
Star Strider
le 19 Jan 2021
1 vote
Since you have R2020a, first, create a table using your data, then use writetable to write it to an Excel file (or other options).
8 commentaires
Gabriela Garcia
le 19 Jan 2021
Star Strider
le 19 Jan 2021
I would use a loop, yes.
It would be straightforward to save them to different files. See: Process a Sequence of Files for an illustration.
Walter Roberson
le 19 Jan 2021
T = table(A51, A52, A53... list them all)
Now T.Properties.VariableNames{K} tells you the original variable name and T{:,K} gives you the content of the Kth of them and you can proceed to write in appropriate format.
This does involve explicitly naming all of the variables once. The options that do not require that are not recommended.
Gabriela Garcia
le 19 Jan 2021
Walter Roberson
le 19 Jan 2021
rownames = {'9:00am','10:00am','11:00am','12:00pm','1:00pm','2:00pm','3:00pm','4:00pm','5:00pm','6:00pm','7:00pm','8:00pm','9:00pm'}
T = table(A51,A52,A53,A54,A55,A56,A57,A58,A59,A60);
names = T.Properties.VariableNames;
nn = length(names);
for K = 1 : nn
arr = T{:,K};
filename = [names{K} '.xlsx'];
tab = array2table(arr, 'VariableNames', {'Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'}, 'rownames', rownames);
writetable(tab, filename);
end
I do not know how the StudentID is intended to fit in.
Note: You said that your arrays were 12 x 8, but you have 13 row names and 7 column names; that needs to be cleared up.
Gabriela Garcia
le 19 Jan 2021
Walter Roberson
le 19 Jan 2021
Open in which program?
Gabriela Garcia
le 19 Jan 2021
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!