Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assuming a number x appears m an array a, possibly more than once, find out the

ID: 2966235 • Letter: A

Question

Assuming a number x appears m an array a, possibly more than once, find out the smallest index of x in a. For example, the smallest index for lin [3 21321] is 3. For a row vector a, find the indices of local maxima, ie; entries larger than its adjacent numbers. For example, the local maxima of [4 2 2 0 3 0 1 0] are 4, 3t and L with indices [1.5,7]. Find out the length of the longest run of x in a vector a. For example, the longest run of 3 in [3 3 1 2 3 4] is the first two entries, which has length 2. Find out the number of different entries in a vector a. For example, there are 4 different entries m vector [2 1 3 2 5 2 1], namely, 1, 2, 3, and 5.

Explanation / Answer

6)

min(find(a==x))

--------------------------------------------------------------------------------------------------------

7)

[val,loc]=findpeaks(a);

% here 'val' will give local maximas and 'loc' will give their indices

---------------------------------------------------------------------------------------------------------

8)

max(diff(find(~(a==x)) )-1)

---------------------------------------------------------------------------------------------------------

9)

unique(a)

---------------------------------------------------------------------------------------------------------

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote