Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6073949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:19:41+00:00 2026-05-23T10:19:41+00:00

I have a matrix ( X ) of doubles containing time series. Some of

  • 0

I have a matrix (X) of doubles containing time series. Some of the observations are set to NaN when there is a missing value. I want to calculate the standard deviation per column to get a std dev value for each column. Since I have NaNs mixed in, a simple std(X) will not work and if I try std(X(~isnan(X)) I end up getting the std dev for the entire matrix, instead of one per column.

Is there a way to simply omit the NaNs from std dev calculations along the 1st dim without resorting to looping?

Please note that I only want to ignore individual values as opposed to entire rows or cols in case of NaNs. Obviously I cannot set NaNs to zero or any other value as that would impact calculations.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:19:41+00:00Added an answer on May 23, 2026 at 10:19 am

    Have a look at nanstd (stat toolbox).

    The idea is to center the data using nanmean, then to replace NaN with zero, and finally to compute the standard deviation.

    See nanmean below.

      % maximum admissible fraction of missing values
      max_miss = 0.6;  
    
      [m,n]   = size(x);
    
      % replace NaNs with zeros.
      inan    = find(isnan(x));
      x(inan) = zeros(size(inan));
    
      % determine number of available observations on each variable
      [i,j]   = ind2sub([m,n], inan);     % subscripts of missing entries
      nans    = sparse(i,j,1,m,n);        % indicator matrix for missing values
      nobs    = m - sum(nans);
    
      % set nobs to NaN when there are too few entries to form robust average
      minobs  = m * (1 - max_miss);
      k       = find(nobs < minobs);
      nobs(k) = NaN;
    
      mx      = sum(x) ./ nobs;
    

    See nanstd below.

      flag = 1; % default: normalize by nobs-1
    
      % center data
      xc      = x - repmat(mx, m, 1);
    
      % replace NaNs with zeros in centered data matrix
      xc(inan) = zeros(size(inan));
    
      % standard deviation
      sx      = sqrt(sum(conj(xc).*xc) ./ (nobs-flag));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an rgb image matrix (height*width*3) represented in doubles. After some manipulations on
I have a matrix of data (the columns represent time, and the rows spectrum
I have a matrix A which I want to convert into a data.frame of
I have a file containing a very very huge matrix, size in millions x
I have an XML file (from somewhere) containing matrix values, which I wish to
I've imported some data from a CSV file in matlab. They are time series
I have a very large matrix (216 rows, 31286 cols) of doubles. For reasons
I have a 2d array (matrix) where I am trying to calculate the biggest
I have this method (Matrix::WriteToArray(double &CopyOfArray)) that I want to write a copy of
Hey! I have matrix class and i want to add, multiply and take transpose

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.