How to calculate Average without receiving 'Inf' as a result.
Show older comments
I am trying to find the average efficiency of this 1 column in MATLAB. I have tried N = mean(EstimatedEff,"omitnan") but get 'Inf' asa result. How can I change my code so I recieve a numerical figure for average efficiency? I have attached the Excel sheet below for reference and Using 2020b. Thankyou!
Accepted Answer
More Answers (2)
Uz = unzip('Matlab Copy.zip')
T1 = readtable(Uz{1}, 'VariableNamingRule','preserve')
NonZeros = nnz(T1{:,1})
NrInf = nnz(isinf(T1{:,1}))
NrNaN = nnz(isnan(T1{:,1}))
NrFinite = nnz(isfinite(T1{:,1}))
mean_of_finite_values = mean(T1{isfinite(T1{:,1}),:})
locs = isfinite(T1{:,1}); % Alternative Approach
NrNonfinite = nnz(~locs)
mean_of_finite_values = mean(T1{locs,:})
Of the 674835 values in the file, there are 0 NaN values, 29 are Inf and 674506 are finite.
.
1 Comment
Star Strider
on 9 Oct 2024
Using the 'omitnan' flag is absolutely pointless in this instance!
The reason is that there are no NaN values at all, only Inf and finite values!
Here is one way:
% create dummy matrix
A = rand(100,1);
A([5 10 24 55 23 60]) = inf;
A([12 56 29 35]) = nan;
mean(A) % simple mean
mean(A,'omitnan') % omitting nan s
mean(A(~isinf(A)),'omitnan') % omitting nan and inf -inf
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!