how to detrend data in multiple dimensions

26 次查看(过去 30 天)
Hey all,
I am stuck on a detrending data problem. I have the following matrix Z:
[X,Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2) + 0.1*X+0.2*Y;
surf(X,Y,Z)
Which consists of function X .* exp(-X.^2 - Y.^2) plus a plane 0.1*X+0.2*Y. Now I want to detrend matrix Z such that only the first function remains. Basically I need to fit a non curved plane trough Z(x,y) and then subtract that from Z(x,y).
In 1d that is easy using detrend(Z) but if I put a matrix in detrend() it will detrend all columns separately.
Any ideas on how to detrend in 2d?
  1 个评论
Takfarinas
Takfarinas 2016-8-23
Try this file exchange function which is a 2d equivalent of the detrend function: https://uk.mathworks.com/matlabcentral/fileexchange/33192-flatten-a-data-in-2d/content/detrend_2d.m

请先登录,再进行评论。

回答(1 个)

Star Strider
Star Strider 2016-8-23
For a relatively simple solution, this comes close to completely detrending your surface:
[X,Y] = meshgrid(-2:.2:2);
Z = X .* exp(-X.^2 - Y.^2) + 0.1*X+0.2*Y;
B = [ones(size(X(:))) X(:) Y(:)]\Z(:);
Zdm = ones(size(X))*B(1) + B(2)*X + B(3)*Y; % Z-Detrending Matrix
figure(1)
surfc(X,Y,Z)
grid on
figure(2)
surfc(X,Y,Z-Zdm)
grid on

类别

Help CenterFile Exchange 中查找有关 Data Preprocessing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by