Problem 729. Flag largest magnitude swings as they occur
You have a phenomenon that produces strictly positive or negative results.
delta = [1 -3 4 2 -1 6 -2 -7];
Marching through this list from beginning to end, mark a value with -1 if it is the greatest magnitude negative yet seen (strictly greater, not equal). Mark it with a one if it has the greatest magnitude in the positive direction (strictly greater, not equal). Just use a 0 if neither of these conditions have been met.
The result for the above example would be:
result = [1 -1 1 0 0 1 0 -1]
Solution Stats
Problem Comments
-
4 Comments
Show
1 older comment
Abhishek Jain
on 16 Sep 2016
Nice question.
Abir Hasan
on 1 Aug 2018
Nice problem
Josh
on 7 Aug 2023
Agreed with first comment, it would be helpful to have more specificity with definition of magnitude "swing" ...perhaps the word "swing" is confusing because it implies some kind of reference point or change from one point to the next, when all that's being considered is the magnitude of each progressive value in comparison to previous max_magnitudes(+ and -)
Solution Comments
Show commentsGroup

ASEE Challenge
- 10 Problems
- 250 Finishers
- Find the biggest empty box
- How long is the longest prime diagonal?
- Flag largest magnitude swings as they occur
- Solitaire Cipher
- Spot the outlier
- How long is the longest prime diagonal?
- Solitaire Cipher
- Implement simple rotation cypher
- Given a window, how many subsets of a vector sum positive
- How many trades represent all the profit?
- Flag largest magnitude swings as they occur
- Make a run-length companion vector
- Spot the outlier
- Find a subset that divides the vector into equal halves
- How long is the longest prime diagonal?
- Find the biggest empty box
Problem Recent Solvers681
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!