How can I do such a "countifs"(excel) process in Matlab?

156 visualizaciones (últimos 30 días)
KO
KO el 18 de Abr. de 2021
Respondida: Saad Arshad el 11 de En. de 2022
How can I do such a "countifs"(excel) process in Matlab?

Respuestas (3)

Stephan
Stephan el 18 de Abr. de 2021
You do it by logical indexing:
A = randi(10,1,15)
CountIf = numel(A(A>5))
gives:
A =
9 7 4 10 1 5 4 8 8 2 5 5 7 8 8
CountIf =
8

Simon Fu
Simon Fu el 6 de Ag. de 2021
Another way is to take advantage of the fact that logical in MATLAB has the value of 1 for true, and 0 for false.
So, using sum function would gives the same result as the previous answer of using numel; i.e.:
A = randi(10,1,15)
CountIf = sum(A>5)
gives:
A =
9 7 4 10 1 5 4 8 8 2 5 5 7 8 8
CountIf =
8

Saad Arshad
Saad Arshad el 11 de En. de 2022
The best way to perform the equivalent of a COUNTIFS function in MATLAB is to first convert your data into a table and then use the GROUPCOUNTS function. Details: https://www.mathworks.com/help/matlab/ref/double.groupcounts.html

Categorías

Más información sobre Data Import from MATLAB 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