how to detrend data in multiple dimensions

9 visualizzazioni (ultimi 30 giorni)
Max Baeten
Max Baeten il 22 Ago 2016
Risposto: Star Strider il 23 Ago 2016
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 Commento
Takfarinas
Takfarinas il 23 Ago 2016
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

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 23 Ago 2016
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

Categorie

Scopri di più su Data Preprocessing in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by