how to detrend data in multiple dimensions
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
Takfarinas
le 23 Août 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
Réponses (1)
Star Strider
le 23 Août 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
0 commentaires
Voir également
Catégories
En savoir plus sur Data Preprocessing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!