matrix

I have a matrix (100000x16) where the columns refer to depths and the rows refer to days and the data is of temperature. Some of the data is faulty i.e. gives readings which are obviously wrong. If every row is a measurement taken every 4 minutes how is it possible to state that if any temperature varies by one degree compared to the next measurement (i.e. the next row) to change it to nan?
cheers

Answers (2)

Robert Cumming
Robert Cumming on 17 Nov 2011

0 votes

something like:
data(data(2:end,:)-data(1:end-1,:)>1)=NaN

3 Comments

ricco
ricco on 17 Nov 2011
I see what you trying to do but it doesnt seem to work. This what ive tried to do so far:
Firstly I made every value outside of a specific range as NaN, which works:
Temp(Temp(:,5:end)<0 | Temp(:,5:end)>30) = NaN;
The I try to do as you said:
Temp(Temp(2:end,:)-Temp(1:end-1,:)>1)=NaN;
I dont know if this isnt working because I have NaN in the matrix? But without doing the first stage the process wouldnt work, as I have values up to 9999 which is when the instrument taking the readings malfunctioned.
cheers
Robert Cumming
Robert Cumming on 17 Nov 2011
it should still work with NaN in your matrix - when you say it doesn;t seem to work - do you get an error message?
ricco
ricco on 17 Nov 2011
No I dont get an error message, it doesnt change the values i.e. I still get values which are greater than 1 degree difference from the next.
Walter Roberson
Walter Roberson on 17 Nov 2011

0 votes

Robert's suggestion of
data(data(2:end,:)-data(1:end-1,:)>1)=NaN
should be close, but his logical matrix will be one element short, which will lead to difficulties.
Ricco, you need to define specifically: when you have two consecutive values that differ by more than 1 degree, is it the first value that should be set to NaN, or the second value? The choice will determine whether Robert's logical array needs to be padded at the beginning or the end.
Also, there should be an abs() wrapped around the difference calculation.

This question is closed.

Tags

Asked:

on 17 Nov 2011

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!