Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

#Day97#100DaysChallenge- Matlab Loops |Determine whether a vector is monotonically increasing-Matlab Cody

#Day97-Determine whether a vector is monotonically increasing-Matlab Cody

Task:
Return true if the elements of the input vector increase monotonically (i.e. each element is larger than the previous). Return false otherwise.
A=[1,2,3,4,5]
True
B=[0,-3,4]
False.

Note: This code can be done using the in-built command. But for the challenge, I am trying to avoid those.

Matlab Code:

function tf = mono_increase(x)

for i=2:1:length(x)

    if x(i-1)>x(i)

        tf=logical(false);

        break;

    else

        tf=logical(true);

    end

end

end

 

Sample Input and Output

 x = [0 1 2 3 -4];

false

 x = [0 1 2 3 4];

true


Click here for video description





Live Support: t.me/matlabirawen



 

   

 

 

 

No comments

Popular Posts

Followers