Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero) - MATLAB Cody - MATLAB Central

Problem 1632. Calculate the Number of Sign Changes in a Row Vector (No Element Is Zero)

Difficulty:Rate

For a row vector:

 V=[7 1 2 -3] 

there is one sign change (from 2 to -3). So, the function you write must return N=1.

For this row vector:

 V=[5 9 -2 7]; 

there are two sign changes, one from 9 to -2 and a second from -2 to 7, thus N=2.

Similarly

 V=[-4 -6 -7 -5 -6] and V=[3 7 6 5 6 7 8 7 6] 

have no sign changes (N=0).

Solution Stats

55.2% Correct | 44.8% Incorrect
Last Solution submitted on Mar 14, 2025

Problem Comments

Solution Comments

Show comments

Group

Cody Challenge Image
Cody Challenge
  • 12 Problems
  • 465 Finishers

Problem Recent Solvers767

Problem Tags

Community Treasure Hunt

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

Start Hunting!
Go to top of page