Flag largest magnitude swings as they occur - MATLAB Cody - MATLAB Central

Problem 729. Flag largest magnitude swings as they occur

Difficulty:Rate
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

46.92% Correct | 53.08% Incorrect
Last Solution submitted on Mar 05, 2025

Problem Comments

Solution Comments

Show comments

Problem Recent Solvers681

Suggested Problems

More from this Author51

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Go to top of page