How to find the total quantity of less than or equal to one element in an array?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have an array a=[1 2 3 4 1 1 9 3 6]. I want to count the numbers which is less than or equal the element 4 in the array. And then, add those quantity and divide by 10.
Example: The 4th element is 4. There are some other elements in this array which is equal or less than of 4. How can I find the total quantity of it?
How can i do that?
2 comentarios
Image Analyst
el 19 de Abr. de 2022
OK, surely this must be your homework, so we can't just do it for you. First read this:
then invest two hours here so you can do what you asked (which is a very, very basic thing):
After that you'll be able to do it yourself and won't get into trouble for turning in our solution as your own.
Next the count of numbers less than 4 is a scalar (6), so what do you mean by "add those quantity"? What quantity? It's a single number 6 so there is nothing to add to it. Do you want to sum all the values less than 4?
Respuestas (1)
Image Analyst
el 19 de Abr. de 2022
Well you didn't answer my questions so I'll just guess at some things
a=[1 2 3 4 1 1 9 3 6]
indexesLessThan4 = a < 4 % A logical vector of 0 or 1
% Count the number
count = sum(indexesLessThan4)
% Get the actual values
valuesLessThan4 = a(indexesLessThan4)
% Sum those up and divide by 10.
result = sum(valuesLessThan4) / 10
0 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!