“Index exceeds 37” when 35 variables?
So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject)So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) So, I’ve been trying to do 3 variable modeling in MATLAB. I have four sets of data (3 variables and one answer), and I’m trying to bet an equation modeling the data. When running the section of the code pasted below, I keep getting "Index exceeds number of array elements. Index must not exceed 37". There are only 35 variables in the code, so I’m not sure why this isn’t working. As far as why I chose this format, I think x and z can be modeled by a quadratic individually, but I figured each variable needed to be the same power, so they’re all 4th power. Any help would be greatly appreciated.
ft = fittype([ …
‘p000 + p100*x + p010*y + p001*z + ‘ …
‘p200*x.^2 + p020*y.^2 + p002*z.^2 + ‘ …
‘p110*x*y + p101*x*z + p011*y*z + ‘ …
‘p300*x.^3 + p030*y.^3 + p003*z.^3 + ‘ …
‘p210*x.^2*y + p201*x.^2*z + p120*x*y.^2 + ‘ …
‘p021*y.^2*z + p102*x*z.^2 + p012*y*z.^2 + ‘ …
‘p111*x*y*z + ‘ …
‘p400*x.^4 + p040*y.^4 + p004*z.^4 + ‘ …
‘p310*x.^3*y + p301*x.^3*z + p130*x*y.^3 + ‘ …
‘p031*y.^3*z + p103*x*z.^3 + p013*y*z.^3 + ‘ …
‘p220*x.^2*y.^2 + p202*x.^2*z.^2 + p022*y.^2*z.^2 + ‘ …
‘p211*x.^2*y*z + p121*x*y.^2*z + p112*x*y*z.^2’], …
‘independent’, {‘x’, ‘y’, ‘z’}, …
‘dependent’, ‘v’);
[fitobject, gof, output] = fit([x, y, z], v, ft);
disp(fitobject) error, curve fitting MATLAB Answers — New Questions









