This problem series invites you to solve two simple problems related to the integer NUMBER FIVE, in order to celebrate Cody's 5th birthday.
In this problem, let's find the top 5 greatest prime numbers along the first non-singleton dimension of an input array.
Example
- If the input is a vector, the output is a length-5 vector containing the top 5 prime numbers of the input sorted in descending order. Append NaNs as needed in the output if the number of primes is less than 5.
x = 1:10; y = [7 5 3 2 NaN];
- If the input is a m-by-n (m >= 5) matrix, the output is a 5-by-n matrix containing the column-wise top 5 prime numbers of the input matrix sorted in descending order. Whenever there are less than 5 primes found in a specific column of the input, simply append NaNs as needed in the same column of the output.
% Input x is a matrix
x = [17 6 3
13 8 17
1 2 5
5 3 7
7 11 2
31 7 6];
% Output y
y = [31 11 17
17 7 7
13 3 5
7 2 3
5 NaN 2];
Previous problem in this series: Spot the First Occurrence of 5
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers346
Suggested Problems
-
Return unique values without sorting
1027 Solvers
-
1247 Solvers
-
807 Solvers
-
Is this triangle right-angled?
6691 Solvers
-
Sums of Multiple Pairs of Triangular Numbers
249 Solvers
More from this Author28
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!