2D data fitting using fit and fittype

조회 수: 76 (최근 30일)
Bruno Rosinus Serrano
Bruno Rosinus Serrano 2021년 2월 15일
편집: Abhishek Gupta 2021년 2월 18일
Hello everyone,
I have a 60x60 2D data set which I want to fit using the fit and fittype function, according to fitobject = fit([x,y],z,fitType).
my arrays are:
x = [1:60]
y = [1:60]
and z is a 60x60 array.
(When I use theese arrays in the curve fitting App it works perfectly fine for fittype: 'poly33'.)
I use the fit function as follows:
Fit_Background = fit([x',y],z,'poly33');
For that I get the following error:
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
What am I doing wrong?

답변 (1개)

Abhishek Gupta
Abhishek Gupta 2021년 2월 18일
편집: Abhishek Gupta 2021년 2월 18일
Hi,
As per my understanding, you are getting an error while fitting the data in x, y, and z. Note that the x, y, z are the column vectors of the same dimension in the 'fit' function. In your case, you can do the same as follows: -
x = [1:60]'; % column vector
y = [1:60]'; % column vector
X = repmat(x,60,1); % get x for all values of z
Y = repelem(y,60); % get y for all values of z
z = rand(60,60); % replace this z with your 60x60 array
Z = z(:); % make z a column vector
Fit_Background = fit([X,Y],Z,'poly33'); % fit
For more information, check out the documentation link below: -

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by