Problem 46102. Determine the sum of diagonal elements in a matrix excluding negative and NaN values

Given a NxN matrix, find the summation of all elements present in the diagonal excluding any negative and NaN values. If all the elements are either negative values or NaN values, return 0.
%Example:
A = [1 0; 0 NaN]; ans = 1;
B = [2 0; 0 -1]; ans = 2;
C = [-1 0; 0 -1]; ans = 0;

Solution Stats

55.26% Correct | 44.74% Incorrect
Last Solution submitted on Apr 14, 2023

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers38

Suggested Problems

Problem Tags

Community Treasure Hunt

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

Start Hunting!