MATLAB Calculating Mean of Columns with NaN Values in Matrix A

  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Average Columns
AI Thread Summary
To calculate the mean of a matrix while ignoring NaN values in MATLAB, the function mean can be used with specific parameters. For the matrix A = [1 2; nan 3; 3 4], the command mean(A, 1, 'omitnan') computes the column-wise mean, resulting in the output [2, 3]. This effectively averages the columns while treating NaN entries as non-existent, ensuring accurate mean calculations.
member 428835
Hi PF!

Given a matrix A = [1 2; nan 3; 3 4], how can I calculate the mean so that the resulting matrix averages the columns but ignores the nan values as non-entries, so that the mean of matrix A outputs [2,3]?

Thanks so much!
 
Physics news on Phys.org
Hey thanks Wrichik Basu! Big help! I appreciate your time!
 
  • Like
Likes Wrichik Basu

Similar threads

Back
Top