export output from a linear regression to Excel
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
T27667
am 29 Jul. 2013
Beantwortet: Marina Fernandez
am 21 Sep. 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 Kommentare
Akzeptierte Antwort
Evan
am 29 Jul. 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 Kommentare
Weitere Antworten (1)
Marina Fernandez
am 21 Sep. 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 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!