Problem 44342. Spot the First Occurrence of 5
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 determine the position (index) of the first occurrence of 5 along the first non-singleton dimension of an input array.
E.g.,
- If the input is a vector, return the index of the first occurrence of 5.
x = [1 2 5 3 5]; y = 3;
- If the input is a matrix, return the index of the first occurrence of 5 in each column. If 5 is not found, simply return 0;
% Input x is a matrix x = [1 2 5 5 9 1 5 6 5];
% Output y y = [2 0 1];
Next problem in this series: The Top 5 Primes
Solution Stats
Problem Comments
-
1 Comment
Aaron Margolis
on 19 Jun 2018
Oof that was tricky but enjoyable. Nested for loops were helpful
Solution Comments
Show commentsGroup

Cody5:Easy
- 31 Problems
- 159 Finishers
- Energy of a photon
- Breaking Out of the Matrix
- The Top 5 Primes
- I Plead the Fifth
- Pentagonal Numbers
- Is this is a Tic Tac Toe X Win?
- Inscribed Pentagon?
- Circle/Pentagon Overlap
- Octoberfest festival
- Polarisation
- Missing five
- ASCII Birthday Cake
- Find the nearest prime number
- Extra safe primes
- 5 Prime Numbers
- Is this is a Tic Tac Toe X Win?
- Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock. Tick. Tock.
- MATLAB Counter
- Basic electricity in a dry situation
- How to subtract?
- Pernicious Anniversary Problem
- 5 Prime Numbers
- Is it really a 5?
- The glass half full
- Pi Digit Probability
- A Simple Tide Gauge with MATLAB
- Predicting life and death of a memory-less light bulb
- Write c^3 as sum of two squares a^2+b^2
- Van Eck's Sequence's nth member
- Sums of Multiple Pairs of Triangular Numbers
- Recaman Sequence - I
- Recaman Sequence - II
- Spot the First Occurrence of 5
- Energy of a photon
Problem Recent Solvers421
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!