I am trying to write data from fitlm model to excel and write a column vector of the name of variables into my excel table
3 次查看(过去 30 天)
显示 更早的评论
Hi,
Here is my code:
clear all
X = xlsread('example.xlsx', 1, 'A2:A857'); %get data from column in excel
Y = xlsread('example.xlsx', 1, 'B2:B857');%get data from column in excel
md1 = fitlm(X, Y); %run correlation test between different variables
T = table([''; 'Intercept'; 'Y']); %create column vector of compared variable names
writetable(T, 'example.xlsx', 'Sheet', 2, 'Range', 'A1'); %add names to spreadsheet
writetable(md1.Coefficients, 'example.xlsx', 'Sheet', 2, 'Range', 'B1'); %add results to spreadsheet
writetable(md1.Rsquared.Ordinary, 'example.xlsx', 'Sheet', 2, 'Range', 'G1'); %add results to spreadsheet
writetable(md1.Rsquared.Adjusted, 'example.xlsx', 'Sheet', 2, 'Range', 'G1'); %add results to spreadsheet
I have two problems:
1. I am returned the following error when trying to create a column vector to add to my spreadsheet's table:
Error using (line 8) Dimensions of matrices being concatenated are not consistent.
2. My second error is when using dot notation to collect the data from md1:
|Undefined function 'write' for input arguments of type 'double'.
Error in writetable (line 121) write(a,filename,varargin{:})
Error in (line 13) writetable(md1.Rsquared.Ordinary, 'example.xlsx', 'Sheet', 2, 'Range', 'F1'); %add results to spreadsheet |
Could you help me solve these problems, please?
0 个评论
采纳的回答
Mandar Patwardhan
2017-5-11
1. To resolve the first problem, you need to correct the syntax of the table command as follows:
clear all
X = xlsread('example.xlsx', 1, 'A2:A857'); %get data from column in excel
Y = xlsread('example.xlsx', 1, 'B2:B857');%get data from column in excel
tbl = table(X,Y,'VariableNames',{'Intercept','Y'});
Also, refer to the documentation of the fitlm function which discusses an example similar to what you are trying to achieve. Fir Linear Regression Using Data in Table
2. For resolving the second problem, take a look at the documentation of the function writetable.
As the documentation suggests, the first argument to this function should be of the type "Table". If you provide md1.Rsquared.Ordinary (or Adjusted), which is a double, it will result in an error.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!