export output from a linear regression to Excel
10 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
T27667
el 29 de Jul. de 2013
Respondida: Marina Fernandez
el 21 de Sept. de 2022
Is it possible to export the output after having performed a linear regression to Excel? In other words, to export the variable generated in Workspace which contains the coefficients, R^2 and so on? Either exporting all properties contained in the variable/output at once or one property at a time? When copy-pasting the coefficients for instance to Excel, the variable names and column labels are not pasted into Excel which is quite annoying.
0 comentarios
Respuesta aceptada
Evan
el 29 de Jul. de 2013
You could store your data in a cell array where the first row of elements are the headings (coefficients, r^2, etc.). Then that cell array could be easily exported to excel so that your headings are included. Here's an example assuming a parabolic fit:
C = [2 1 1]; %fit coefficients
Rsq = .8933; %r^2 value
data = [num2cell(C) num2cell(Rsq)]; %data in cell array form
data = [{'x^2' 'x^1' 'x^0' 'r^2'};data] %add columns
xlswrite('my_table.xls',data)
This will also work if C and Rsq contain multiple rows of data in the case of multiple fits.
0 comentarios
Más respuestas (1)
Marina Fernandez
el 21 de Sept. de 2022
Another option is to convert the model to text, separate it by rows and convert that to a cell in order to write the results of the model in excel format:
text_model = evalc('disp(model)');
split_text_model = split(text_model,char(10));
xlswrite(excel_path,cellstr(split_text_model),'results','A1');
0 comentarios
Ver también
Categorías
Más información sobre Descriptive Statistics 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!