how to detrend data in multiple dimensions

조회 수: 21 (최근 30일)
Max Baeten
Max Baeten 2016년 8월 22일
답변: Star Strider 2016년 8월 23일
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