xlswrite is not recommended, what should I use instead?
Ältere Kommentare anzeigen
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?
Antworten (1)
Star Strider
am 19 Jan. 2021
1 Stimme
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 Kommentare
Gabriela Garcia
am 19 Jan. 2021
Star Strider
am 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
am 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
am 19 Jan. 2021
Walter Roberson
am 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
am 19 Jan. 2021
Walter Roberson
am 19 Jan. 2021
Open in which program?
Gabriela Garcia
am 19 Jan. 2021
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!