Counting the occurrence of a value=Inf in an array
23 Ansichten (letzte 30 Tage)
Paras Gupta am 6 Jul. 2022
It is my understanding that you need a function to find the total number of 'Inf' values in a given array. Though there does not seem to be any one particular function to find the same, you can very easily find the solution using two functions as is illustrated in the following code.
R = [1; 2; 3; 4; 5; 6; Inf; 7; Inf];
% isinf returns a logical array with true (1) at indices where element is inf
% nnz returns the number of non-zero values in the array
infCount1 = nnz(isinf(R))
% one could also use sum function instead of nnz
infCount2 = sum(isinf(R))
You can refer to the following documentations on isinf, nnz, and sum for more information on how the above code works.
Hope it helps!