Obtaining a equation in two variables (x and y) from a set of data points

14 ビュー (過去 30 日間)
Akaash Dragon
Akaash Dragon 2019 年 11 月 25 日
コメント済み: Akaash Dragon 2019 年 12 月 4 日
I have a Matrix. The colums represent the X values and the rows represent the Y values and the matrix element Z represents the value at (X,Y). So, in my case, X runs from 1 to 250 and Y runs from 1 to 3500. I would like to fit an equation (I suspect that the data is going to be of high order *say 50) so maybe spline?) such that Z=f(X,Y) where Z is the matrix element
Example :
Say I choose X=10 and Y=2300 in the matrix. The matrix will have a particular value Z (say 30000) at (10,2300). Now I want to fit a equation for Z as a function of X and Y. What do I do?

採用された回答

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 11 月 25 日
What you should do depends on your objective. If you very explicitly want a function you could use spap2 (and perhaps some of its siblings). It is a least-square-fitting spline function with 2-D capabilities.
If you can do all of the function evaluations at once you might be better off with interp2 (your data seems to be on a plaid grid), or griddata, scatteredInterp, triscatteredinterp functions (the latter might give you approximately your required function output), Otherwise there is always the gridfit function on the file exchange.
HTH
  6 件のコメント
Akaash Dragon
Akaash Dragon 2019 年 12 月 4 日
f2=csapi({x_r,y_r},f);
fnval(f2,[3;100])
These commands work.
Note that f2 structure looks like this:
form: 'pp'
breaks: {[1×3500 double] [1×250 double]}
coefs: [1×13996×996 double]
pieces: [3499 249]
order: [4 4]
dim: 1
However it doesn't work well if I use spap2. Using your code gives me something like this
Error using repmat
Requested 609000000x6 (27.2GB) array exceeds maximum array size preference. Creation of arrays greater than this
limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for
more information.
Error in spval>spval1 (line 104)
tx =reshape(t(repmat(2-k:k-1,d*lx,1)+repmat(dindex,1,2*(k-1))),d*lx,2*(k-1));
Error in spval (line 43)
spval1(spmak(t{i},reshape(v,prod(sizev(1:m)),sizev(m+1))), ...
Error in fnval (line 95)
v = reshape(feval(ff,f,varargin{:}),[sizeval,sizex]);
Error in flats>@(x,y)fnval(bsp2,{x(:),y(:)})
Error in flats (line 17)
Z(:) = your_fun(X,Y);
This is the error I get.
Spap2 seems to be better than csapi and hence would prefer if you could help me use fnval with spap2. Thanks in advance!
Akaash Dragon
Akaash Dragon 2019 年 12 月 4 日
fnval(bsp2,[3;100])
This command works! Thank you very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpline Postprocessing についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by