Effacer les filtres
Effacer les filtres

Temperature data

3 vues (au cours des 30 derniers jours)
ricco
ricco le 4 Nov 2011
Does anyone know of the best way to do the following:
I have temperature data for a lake which is taken every 2 meters, the data is located in a matrix with each 2 meter measurement in a separate column and each row representing a different time. What would be the best way to include a statement which states that if any value varied more than 2 degrees Celsius from the next column (in the same row) to be counted as NaN?
Any suggestions would be great!
cheers

Réponses (2)

Wayne King
Wayne King le 4 Nov 2011
Is it "varied more than 2" in absolute value? or just greater than? Let X be the data matrix.
Y = abs(diff(X'));
X(Y>2) = NaN;
Not sure what value you want to replace with the NaN.
For example if the first column is 7 and the second column is 2, do you want to put a NaN in the first column??
  2 commentaires
Walter Roberson
Walter Roberson le 4 Nov 2011
Careful, diff(X) will be smaller than X: you would need to pad Y to use it it as a logical index.
And be careful because you transposed X to get Y but then you index X at the untransposed Y.
Using diff(X,2) would avoid the transpose.
ricco
ricco le 4 Nov 2011
During some instances the temperatures vary by up to 7 degrees celsius depending on the time of year but they dont vary by 2 degrees with respect to the next depth (i.e. next column).
So, ideally the location of the NaN would depend on the other values in the same row. So, if the first column is 7 then the second is 2 then the third is 8 then i would need the second column to be NaN.
The threshold value doesnt have to be 2 degrees but the temperatures do not vary more than 2 with respect to the next depth (i.e. column)unless there is a fault in which case im trying to remove them.
cheers

Connectez-vous pour commenter.


Andrei Bobrov
Andrei Bobrov le 4 Nov 2011
[a,b] = find(diff(yourdata,1,2)>2)
yourdata(sub2ind(size(yourdata),a,b+1)) = nan
variant 2
s = size(yourdata);
z = zeros(s(1),1);
t1 = [z yourdata z];
m = arrayfun(@(x)median(reshape(t1(x, hankel(1:3,3:s(2)+2)),3,[]) ),1:s(1),'un',0);
tst = abs(yourdata - cell2mat(m.')) > 2;
yourdata(tst) = nan;

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by