Ignore NaN
Occasionally I record missing data, invalid data or erroneous data as NaN. But if I have a array of data where the columns are different measurements and the rows are different measurement times the NaNs make it difficult to perform statistical operations on.
This Function will perform a function on the data (assuming the function is designed to operate on an array) but it will ignore any NaNs.
For example
X=[ 1 2 4;
1 5 NaN;
NaN 3 1]
std(X)
ans =
NaN 1.5275 NaN
>> ignoreNaN(X,@std)
ans =
0 1.5275 2.1213
This function is designed to work on any size array.
Cite As
Matt G (2023). Ignore NaN (https://www.mathworks.com/matlabcentral/fileexchange/15776-ignore-nan), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- MATLAB > Language Fundamentals > Data Types > Numeric Types > NaNs >
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 | correction for case of size(X,2)=1, and nargin==2 |