export output from a linear regression to Excel

10 次查看(过去 30 天)
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.

采纳的回答

Evan
Evan 2013-7-29
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.

更多回答(1 个)

Marina Fernandez
Marina Fernandez 2022-9-21
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');

Community Treasure Hunt

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

Start Hunting!

Translated by