Polynomial 2nd degree
显示 更早的评论
I tried using the curve fitting tool, however i had an error saying that 'Data sizes are incompatible.'
dataset= xlsread('ML.xlsx','sheet2')
a=dataset(:,1)
S=dataset(:,3:9)
D= repelem(a(1:end, :), 1, 7)
cftool
4 个评论
dpb
2019-4-8
What are the other columns? Seven different sets of observations to fit to the same X vector, or what?
Not enough information to know what is wanted/expected to be fit to what, specifically.
Image Analyst
2019-4-8
You forgot to attach 'ML.xlsx'.
You can only fit one set of y to a set of x. You can't fit 7 y simultaneously to one x.
Why do you think you should get 7 coefficients for a quadratic? You should get only 3 for each set of y values, so 21 total if you have 7 sets of y.
dpb
2019-4-12
I've no idea what you think
SalMax=repelem(Salinity(1:end, :), 1, 7)
is for or doing but to fit a higher order polynomial with polyfit you just set the desired order; it does everything else automagically.
Attach the data set; the first step in any fitting problem is to visualize the data...we can't do anything with only the response variable.
dpb
2019-4-13
I'll try to look at the data some this evening; that will help some...meanwhile you've not really yet given any meaningful context to what the other variables are and I have no idea what " a sailinty column and different bands paremeters ( 7 columns), from which i need to generate a predicted salinity and eventually the equation that i would use in GIS" actually means or how that bears upon the problem.
What are "different band parameters"? Without any idea at all of what data are it's tough to have any klew as to what makes any physical sense at all...just because one could find a set of variables and a polyfit of given degree doesn't mean one should.
采纳的回答
更多回答(1 个)
dpb
2019-4-9
Taking a shot that the presumption earlier is the correct one--
xy=xlsread('ML.xlsx','sheet2'); % read the data into array
N=size(xy,2)-1; % there are one fewer y vectors than columns in array
mdl=cell(N,1); % create an empty cell arrray to hold fit results
for i=1:N % for each "y" column
mdl(i)={fitlm(xy(:,1),xy(:,i+1),'purequadratic')}; % fit the quadratic, store in cell array
end
will result in a Nx1 cell array holding the N linearmodel objects. To see each, just dereference the cell content with the curlies (braces). I just did one with a set of randn() values so the coefficients are near zero, but you get the following output by default. See the doc for fitlim and link to the linearmodel properties to see all about it...
>> mdl{1}
ans =
Linear regression model:
y ~ 1 + x1 + x1^2
Estimated Coefficients:
Estimate SE tStat pValue
________ ____ _____ ______
(Intercept) -0.05 0.71 -0.07 0.95
x1 0.03 0.16 0.22 0.83
x1^2 -0.00 0.01 -0.66 0.52
Number of observations: 20, Error degrees of freedom: 17
Root Mean Squared Error: 0.95
R-squared: 0.17, Adjusted R-Squared 0.0722
F-statistic vs. constant model: 1.74, p-value = 0.206
>>
4 个评论
moeJ
2019-4-12
dpb
2019-4-13
Would need to see some of the typical data and know more about what you're really trying to fit and what the variables are (some things that one can do just don't necessarily make any sense to do)...
Obviously, one should always start off on a fitting expedition by first visualizing the data...
Image Analyst
2019-4-13
编辑:Image Analyst
2019-4-13
Despite a strong hint from me and a direct request from dpb, you've still not attached your data, 'ML.xlsx'. Why not? Please do so if you want good answers from here on out.
moeJ
2019-4-13
类别
在 帮助中心 和 File Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


