Problem 14. Find the numeric mean of the prime numbers in a matrix.
There will always be at least one prime in the matrix.
Example:
Input in = [ 8 3 5 9 ] Output out is 4 or (3+5)/2
Solution Stats
Problem Comments
-
12 Comments
2 is prime, so the example solution should be (2+3+5)/3 = 3.33....
+1, the example is wrong :(
*blushing* Oops! At least we got the actual test suite right. Thanks for the notes. Fixed it.
i didn't understand the problem
good one...
I don't understand why this doesn't work for test 3: out=sum(in.*isprime(in))/sum(isprime(in))
it works for all other tests but test 3 requires an answer of 3 and the code gives an answer of 3.0000. Can anyone tell me why?
funny :)
good
Good one
The question topic is hard to understand.
Good Problem for beginners.
What is wrong with
a = find( isprime( in))
out = mean( in( a)) ?
It works perfectly in my own MATLAB environment
Solution Comments
Show commentsProblem Recent Solvers9051
Suggested Problems
-
Determine whether a vector is monotonically increasing
22200 Solvers
-
It dseon't mettar waht oedrr the lrettes in a wrod are.
2024 Solvers
-
given 3 sides, find area of this triangle
811 Solvers
-
Given a window, how many subsets of a vector sum positive
862 Solvers
-
Calculate the area of a triangle between three points
3305 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!