Borrar filtros
Borrar filtros

How do I find the percentage of a number of values within a certain range?

27 visualizaciones (últimos 30 días)
I have a number of values which represent the differences between two surfaces. I would like to know the percentage of values which lie within a certain range e.g 0.05 and -0.05? How would I go about finding these values and then working out what percentage of the total?

Respuesta aceptada

Stephen23
Stephen23 el 28 de Abr. de 2017
Editada: Stephen23 el 28 de Abr. de 2017
>> M = rand(6,7)-0.5; % matrix of fake data
>> X = -0.05<M & M<0.05; % check conditions
>> nnz(X)/numel(M)
ans = 0.095238
9.5% of the values of M are within the given conditions.

Más respuestas (1)

Guillaume
Guillaume el 28 de Abr. de 2017
Editada: Guillaume el 28 de Abr. de 2017
sum(x > -0.05 & x < 0.05) / numel(x) %number of values between -0.05 and 0.05 divided by total number
Or if you want to do that with several interval, use histcounts with the 'Normalization', 'probability' option.
histcounts(x, -3.5:3.5, 'Normalization', 'probability'); %for example for 6 bins

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by