xlswrite formatting error. Naming multiple sheets

2 visualizaciones (últimos 30 días)
Stephen Dzuryk
Stephen Dzuryk el 5 de Sept. de 2018
Abierta de nuevo: Walter Roberson el 22 de Dic. de 2018
I am very new to MATLAB.
Currently, I have to use the following code to export my data to Excel but would like to reduce the number of lines needed if possible and change the "sheet" name of all of them at once.
Data = {'MATLAB DATA'};
Data1 = {'Reactor Length (m)', 'Molar flow of A (mol/s)', 'Molar flow of B (mol/s)', 'Molar flow of C (mol/s)', 'Molar flow of D (mol/s)','Reaction Rate (mol/(m^3*s))'};
Data2 = [Z Fa Fb Fc Fd rA2];
Data3 = {'Reactor Radius (m)', Ro}
Data4 = {'Reactor Pressure (Bar)', P_Bar}
Data5 = {'Reactor Temperature (K)', T}
xlswrite('PFR_Data.xlsx', Data, '3 H2 1 CO2', 'A1:A6')
xlswrite('PFR_Data.xlsx', Data1, '3 H2 1 CO2', 'A3')
xlswrite('PFR_Data.xlsx', Data2, '3 H2 1 CO2', 'A4')
xlswrite('PFR_Data.xlsx', Data3, '3 H2 1 CO2', 'A2')
xlswrite('PFR_Data.xlsx', Data4, '3 H2 1 CO2', 'C2')
xlswrite('PFR_Data.xlsx', Data5, sheet, 'E2')
When I try
sheet = {'5 H2 1 CO2'}
xlswrite('PFR_Data.xlsx', Data, sheet, 'A1:A6')
I get the following error
Error using xlswrite (line 172)
Sheet argument must be a character vector or a whole number greater than 0.
Any help will be appreciated.

Respuesta aceptada

Bob Thompson
Bob Thompson el 5 de Sept. de 2018
Editada: Bob Thompson el 5 de Sept. de 2018
Using sheet = {} defines the variable 'sheet' as a cell containing a character string with the name. If you do sheet{1} or something similar that should be the quickest solution.
Alternatively, you should be able to define sheet without the cell brackets.
sheet = '5 H2 1 CO2';
which should define sheet just as the sheet string name, rather than as a cell containing the name.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by